Folding a strip of paper, forever
Take a long strip of paper and fold it in half, always in the same direction. Do it once: one crease. Do it four times and unfold every crease to a right angle: you get the Heighway dragon, the same curve NASA engineers noticed on the margins of blueprints and the same one that decorated the cover of Michael Crichton's Jurassic Park. The physical folding is a nice story, but the curve is really defined by a much simpler object: a string of L and R turns that doubles in length at every step.
Start with the single-symbol sequence L. To go from generation n to n+1, copy the sequence, insert an L in the middle, then append the reverse of the original sequence with every symbol flipped (L↔R). This is the exact rule a strip of paper obeys when you fold it in half and always fold the same way: each new fold reflects and reverses everything that came before it.
Turtle graphics: turning strings into pixels
Once you have the turn sequence for a given generation, drawing it is a turtle graphics problem: walk forward a fixed step length, and at each symbol turn 90° left (L) or 90° right (R), then draw the next segment. No trigonometry beyond four fixed headings (0°, 90°, 180°, 270°) is needed, which is why the curve renders instantly even at high iteration counts — every segment is axis-aligned.
function nextGen(seq) {
// seq is an array of +1 (L) / -1 (R)
const mid = 1; // insert an L (+1) in the middle
const tailRev = [...seq].reverse().map(t => -t);
return [...seq, mid, ...tailRev];
}
let heading = 0; // 0,1,2,3 = N,E,S,W as multiples of 90°
for (const turn of turnSeq) {
x += DX[heading] * step; y += DY[heading] * step;
drawLineTo(x, y);
heading = (heading + turn + 4) % 4;
}
An equivalent and often faster route skips string-building entirely: the turn before step n (1-indexed) is determined directly by the position of the lowest set bit that is 0 in the binary representation of n, an old bit trick discovered independently by several people studying the dragon curve's self-similarity. This lets you jump to segment number 131,072 without ever materialising the first 131,071.
Self-similarity and the boundary that tiles the plane
The dragon curve is built from two half-size copies of itself, each rotated 45° and scaled by 1/√2, joined at their tips — a direct consequence of the fold-and-reflect rule. This self-similarity gives it a fractal dimension of exactly 2: even though it is drawn as a one-dimensional path, at high enough iteration it fills area, and its boundary is itself a fractal curve of dimension roughly 1.5236. Despite constantly crossing near itself, the curve as generated by this L-system never crosses itself — a property proved rigorously by Chandler Davis and Donald Knuth in their 1970 paper on the dragon curve and other paperfolding sequences.
Perhaps the most striking fact: four copies of the dragon curve, rotated by 90° increments around a common centre, tile the plane with no gaps and no overlaps. The curve is, in the strict mathematical sense, a rep-tile — it can be dissected into smaller copies of itself, and larger copies of it exactly tile using smaller copies. This connects it to a whole family of paperfolding curves (the Lévy C curve, the terdragon) built by the same idea with different fold angles or fold counts per step.
Why generation 17 already has 131,072 segments
Each generation doubles the previous segment count: generation n has 2ⁿ segments. That is why a modest-looking on-screen curve after only 17 folds already needs 131,072 line segments — and why any implementation that recomputes the full string from scratch every frame will start to stutter well before generation 20. The fix used in this simulation is the same one used across the site's other L-system fractals: precompute the full turn sequence once per generation change with the doubling recurrence above (linear time, not exponential), then only redraw when the generation or step size actually changes.
Frequently asked questions
Does the Heighway dragon curve ever cross itself?
No. Although segments pass very close to each other and the curve appears dense at high generations, Davis and Knuth proved in 1970 that the standard paperfolding dragon curve never self-intersects, no matter how many folds you take.
Why does the segment count double every generation?
Each fold doubles the length of the paper strip, and unfolding it inserts one new crease between every pair of existing segments plus the original ones reflected — so generation n always has exactly 2ⁿ segments, an exponential growth that is the reason high generations need efficient turn-sequence math rather than brute-force redraws.
Is the dragon curve related to origami or fractals used in nature?
It's a mathematical idealization of real paper folding, not a natural fractal like a coastline or fern. But it belongs to the same paperfolding-sequence family as the Lévy C curve and terdragon, and its boundary has a genuine fractal dimension (~1.5236) even though the filled curve itself has dimension 2.
Try it live
Everything above runs in your browser — open Dragon Curve and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Dragon Curve simulation