🐉 Dragon Curve — Heighway Turn-Sequence Fractal
Generate the Heighway dragon curve from its recursive L/R turn sequence and watch it unfold via turtle graphics. Adjust the iteration depth, animate the draw-in speed, and color the curve by depth.
Generate the Heighway dragon curve from its recursive L/R turn sequence and watch it unfold via turtle graphics. Adjust the iteration depth, animate the draw-in speed, and color the curve by depth.
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.
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.
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.
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.
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.
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.
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.
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.
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.