🐉 Dragon Curve
Generate the Heighway dragon curve from its recursive L/R turn sequence and watch it unfold via turtle graphics. Adjust the iteration depth up to 17, animate the draw-in speed, and color the curve by depth.
About this simulation
This tool generates the Heighway dragon curve, a self-similar fractal built from a recursively doubled sequence of left and right turns. Starting from the empty turn sequence, each iteration doubles it by appending an R and the reversed, letter-swapped copy of the previous sequence. A turtle then walks the sequence, turning at each symbol, tracing the folded dragon shape one straight segment at a time.
🔬 What it shows
The turn sequence is built by the recurrence seq(n) = seq(n−1) + R + reverse(complement(seq(n−1))), starting from the empty string. Walking a constant-length segment and turning left or right according to each symbol traces 2n straight segments joined at 2n−1 turns, producing the folded dragon shape.
🎮 How to use
Drag the iteration slider to grow the curve from a single segment up to 217 segments, and use the draw speed slider to slow down or speed up how quickly new segments appear. Toggle Color by depth to shade each segment by its position along the path, and press Reset / Recenter to refit the curve to the canvas.
💡 Did you know?
The dragon curve gets its name from the way it looks like a coiled dragon at moderate iterations, and it is exactly the shape you get by folding a strip of paper in half the same way each time and then unfolding every crease to a right angle.
Frequently asked questions
What is the dragon curve?
The dragon curve (or Heighway dragon) is a self-similar fractal traced by repeatedly folding a strip of paper in half and unfolding each crease to a right angle. It can also be generated purely from a sequence of left and right turns without any paper at all, and it belongs to the same family of curves as the Lévy C curve and other paperfolding fractals.
How is the turn sequence generated?
It is built by doubling: starting from the empty sequence, each new iteration is formed by taking the previous sequence, appending an R, and then appending the reverse of the previous sequence with every L and R swapped. This recurrence, seq(n) = seq(n-1) + R + reverse(complement(seq(n-1))), produces a string of length 2^n - 1 describing every turn along the path.
Why doesn't the dragon curve cross itself?
Even though the curve folds back on itself many times, it can be proven that the Heighway dragon never self-intersects. Adjacent segments always meet only at their shared endpoint, which is why the boundary looks jagged and space-filling but the path itself stays a simple, non-crossing curve.
What is the fractal dimension of the dragon curve?
The dragon curve has a fractal (Hausdorff) dimension of exactly 2, even though it is a one-dimensional curve embedded in the plane. This reflects how tightly the path folds back on itself: at high iterations it comes close to tiling the plane, which is also why copies of the dragon curve can tile the plane exactly.
Why does higher iteration take longer to draw?
Each additional iteration doubles the number of segments, so the number of straight-line pieces to draw grows as 2^n. At n = 17 that is 131,072 segments, so the animation naturally takes more draw-in frames at high iteration counts even though each individual segment is computed instantly.
Generate the Heighway dragon curve from its recursive L/R turn-sequence doubling rule and watch it unfold via turtle graphics, up to 131,072 segments.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install