diff --git a/Readme.md b/Readme.md index fc21591..8083c9b 100644 --- a/Readme.md +++ b/Readme.md @@ -17,6 +17,131 @@ collection of single-file C programs. --- +## Tutorial + +This tutorial walks through every stage of the simulation as it appears in +`rope.c`, from initial state to rendered frame. + +### 1. Simulation Constants and State Arrays + +The simulation is controlled by a handful of compile-time constants and two +pairs of parallel arrays that hold current and previous positions for each +node: + +```c +#define W 80 /* terminal width */ +#define H 40 /* terminal height */ +#define N 24 /* number of nodes */ +``` + +```c +double x[N], y[N]; /* current positions */ +double px[N], py[N]; /* previous positions (Verlet history) */ +``` + +All nodes are initialised in a horizontal line near the top of the screen: + +```c +for (int i=0;i= 1`) the new position is computed from the current +position, the previous position (which encodes velocity implicitly), a damping +factor of `0.99`, and a constant gravity term of `0.05` per frame: + +```c +for (int i=1;i=0&&ix=0&&iy