Koch snowflake: one rule builds a complex boundary
Start with an equilateral triangle. A small triangular bump grows on each side. Apply the same rule to every new segment, and the simple outline becomes more detailed. Step through the construction and compare how its perimeter and area change.
Video walkthrough
One segment becomes four
Divide a segment into three equal parts. Build an outward-facing equilateral triangle on the middle third, then remove its base. The straight segment becomes a broken line of four segments, each one third of the original length.
Apply this replacement to every segment of the current outline. Complete the entire iteration before replacing any newly created segment. Each replacement keeps the original endpoints, so adjacent parts still form a closed outline.
The first replacement in coordinates
Take the segment from A=(0,0) to B=(1,0). The points dividing it into three equal parts are (1/3,0) and (2/3,0). The bump's tip is at (1/2,−√3/6). Including both endpoints, the broken line has five points and four segments of length 1/3.
The sign before √3 selects the side of the bump. The model traverses the starting triangle counterclockwise in mathematical coordinates, with y pointing up. Its interior is to the left of each directed edge, so the bump goes to the right. Drawing flips the y-axis. The same vector rotation handles every edge; there are no separate rules for upper and lower sides.
What the interactive counts
Iteration 0 is the starting triangle with three sides. After n replacements, the outline has Nₙ=3·4ⁿ segments, each of length sₙ=s₀/3ⁿ. Here s₀ is the original triangle's side length, set to 1 in the model.
One playback step shows one completed iteration. The slider and buttons return to any saved outline. A dashed line overlays the previous iteration; orange marks the two new sides of each bump, while blue marks the first and last thirds. Toggling the overlay keeps the current iteration.
In the table, P₀ is the starting triangle's perimeter and A₀ its area. Every number describes the finite polygon currently displayed, rather than an infinite boundary.
| n | N | Segment / s₀ | Pₙ / P₀ | Aₙ / A₀ |
|---|---|---|---|---|
| 0 | 3 | 1/1 | 1 | 1 |
| 1 | 12 | 1/3 | 1.3333 | 1.3333 |
| 2 | 48 | 1/9 | 1.7778 | 1.4815 |
| 3 | 192 | 1/27 | 2.3704 | 1.5473 |
| 4 | 768 | 1/81 | 3.1605 | 1.5766 |
| 5 | 3,072 | 1/243 | 4.214 | 1.5896 |
| 6 | 12,288 | 1/729 | 5.6187 | 1.5954 |
Why the boundary gets longer
A segment of length L becomes four segments of length L/3. Their total length is 4L/3, so every iteration multiplies the entire perimeter by 4/3: Pₙ=P₀·(4/3)ⁿ.
For a triangle with side length 1, the initial perimeter is 3. Subsequent values are 4, 16/3, 64/9, and so on. The multiplier exceeds one, so continuing indefinitely produces unbounded perimeters. Every stage with a chosen finite number of iterations still has a finite perimeter.
Why the area stays finite
The first iteration adds three triangles with side length s₀/3. Each has area A₀/9; together they add A₀/3. The next iteration adds four times as many triangles, but each has one ninth the area. Each successive area increment is therefore 4/9 of the previous increment.
Summing the increments through n iterations gives Aₙ/A₀=8/5−(3/5)·(4/9)ⁿ. At n=0 this is 1; after the first iteration it is 4/3. As n grows, the last term tends to zero and the area approaches 8A₀/5, or 1.6 times the starting triangle's area.
Length and area measure different properties. New segments lengthen a trip around the boundary, while the added triangles occupy ever less space. A bounded area is therefore compatible with unbounded growth in boundary length.
The same structure at a smaller scale
Each of the snowflake's three sides develops into a Koch curve. Its construction consists of four copies of the previous construction, scaled by one third, rotated and translated. Zooming into a portion reveals the same way of joining segments.
The screen shows finite stages. The limiting curve has detail at every scale, while a raster image has a fixed pixel size. Once short segments blend together, further model detail is difficult to distinguish on the same screen.
Executable construction code
The code below returns the same outline's vertices in the same order. Connect the last vertex back to the first; the array does not repeat its first point. Each old edge contributes the four starting points of its new segments. Its endpoint becomes the next old edge's start.
The iterative implementation builds a separate next array, preserving the old outline until the replacement is complete. The player additionally freezes points and arrays and retains all iterations for backward seeking. Calculations use JavaScript numbers; only displayed labels are rounded.
Show executable code
function kochSnowflake(iterations = 5) {
if (!Number.isInteger(iterations) || iterations < 0 || iterations > 6)
throw new RangeError("Use 0–6 iterations");
let points = [{ x: 0, y: 0 }, { x: 1, y: 0 },
{ x: 0.5, y: Math.sqrt(3) / 2 }];
for (let n = 0; n < iterations; n++) {
const next = [];
for (let i = 0; i < points.length; i++) {
const a = points[i], b = points[(i + 1) % points.length];
const dx = b.x - a.x, dy = b.y - a.y;
next.push(
{ x: a.x, y: a.y },
{ x: a.x + dx / 3, y: a.y + dy / 3 },
{ x: (a.x + b.x) / 2 + Math.sqrt(3) * dy / 6,
y: (a.y + b.y) / 2 - Math.sqrt(3) * dx / 6 },
{ x: a.x + 2 * dx / 3, y: a.y + 2 * dy / 3 }
);
}
points = next;
}
return points; // Close the last vertex back to the first when drawing.
}Construction cost and detail limits
Iteration n has 3·4ⁿ segments. Building stages 0 through n takes O(4ⁿ) time: the processed edge counts form a geometric sum. A single final outline needs O(4ⁿ) memory. All saved outlines also take O(4ⁿ), because their total size is bounded by a constant multiple of the last outline's size.
The playback history contains n+1 small states with iteration indices. They refer to precomputed outlines without duplicating them. Drawing stage k visits O(4ᵏ) segments. The interface allows 0–6 iterations: the sixth already has 12,288 segments. This is a practical interface limit, not a restriction on the mathematical construction.
Things to try
Choose one iteration and press Next. Three sides should become twelve; both perimeter and area increase by a factor of 4/3. Increase the iteration limit and check again: the perimeter keeps gaining a factor of 4/3, while each area increment is smaller than the preceding one.
Enable the previous outline and find the replacement of one edge between adjacent stages. Then disable the overlay to inspect only the current snowflake. Compare stages four and six: there is much more detail, but the area ratio changes only a little.
Share the player state. The link preserves the iteration limit, current stage, speed and previous-outline setting. It opens the standalone interactive paused.