Koch Snowflake
Drag the slider for the step n from 0 to 5: each step replaces the middle third of every side by two sides of a triangle, and the snowflake grows.
Helge von Koch described this curve in 1904. Start from an equilateral triangle and replace the middle third of every side by the two other sides of a smaller equilateral triangle that points outward; then repeat. After n steps the curve has 3 \cdot 4^n sides of length \sqrt{3}/3^n . Its length grows as (4/3)^n , without bound, but the area inside it stays below 8/5 of the area of the triangle.
The document's prelude computes the vertices of steps 0 to 5 once, when the document opens, into one list Q . A step is not built from the one before it: the direction of side k follows from the base-4 digits of k (a digit 1 turns the side by +60° , a digit 2 by -60° , and 0 and 3 do not turn it), so one loop walks the sides. Step n has M = 3 \cdot 4^n + 1 vertices, the last equal to the first, and starts after the o = 2(4^n - 1 + n) numbers of the steps before it.
The slider for n runs from 0, the triangle, to 5, and opens at 4. Step 5 has 3072 sides, each about 1/500 of the width of the view, so a further step would not change the picture.
JavaScript is required to view the interactive plot.