Draw Levy Fractal

Draw the Lévy C-curve (Paul Lévy 1938) - space-filling fractal at 45°. Gradient and segmented modes. Free, offline, client-side, instant, secure.

Paul Lévy's 1938 space-filling curve via L-system (axiom F, rule F → +F--F+, 45° turns).

How to Use Draw Levy Fractal

  1. Pick iteration level (1-14). Each iter doubles segment count: iter N = 2^N. Iter 11 = 2,048 (default), iter 14 = 16,384. Iter ≥ 13 triggers the "Drawing…" loading state.
  2. Choose render mode: Continuous (single primary-color stroke), Gradient (primary → secondary lerp along traversal), Segmented (alternating per segment for high-contrast self-similarity demos).
  3. Pick colors. Primary (always used) + secondary (gradient and segmented only). Low-contrast primary-vs-background triggers an info-toast warning.
  4. Set canvas size and background. HiDPI-aware (backing store × DPR for crisp Retina). Background: white, black, or transparent.
  5. Adjust line width (1-5 px). Thinner lines (1-2 px) work better for iter 12+ to avoid the curve becoming a solid blob.
  6. Press Ctrl+Enter (or Cmd+Enter on Mac) or click Draw. Stats show: segments, dimension (2.0 - space-filling), iteration, total path length, L-system char count, render time.
  7. Copy or Download. Copy puts PNG bytes on clipboard via ClipboardItem. Download saves levy-c-curve-iter-N.png.

Frequently Asked Questions

What is the Lévy C-curve?

Discovered by French mathematician Paul Lévy in 1938 (full name: Paul Pierre Lévy, 1886-1971; not the same as Pierre Léonidas Lévy who studied dragon curves). Defined by an L-system with axiom F and rule F → +F--F+ at 45° turns. Each iteration doubles the segment count. The limit set is truly space-filling (dimension 2) with strong self-overlap – the curve passes through the same plane region multiple times. Named “C-curve” because at iter 6-10 it resembles the letter C or a curled dragon.

Why is dimension exactly 2?

Self-similarity formula: dim = log(N)/log(S) where N copies are placed at scale 1/S. Lévy: each F is replaced by 2 F’s via the rule (after +/- turns cancel through the recursive expansion), placed at scale 1/√2 each (45° turn creates a √2 hypotenuse split into 2 half-length sub-segments). So dim = log(2)/log(√2) = log(2)/((1/2) log(2)) = 2. Dimension 2 = truly space-filling.

How does it differ from the Heighway dragon?

Both are 2D space-filling curves with dimension 2. Heighway dragon (1966, NASA): paper-folding construction, 90° turns, rule X → X+YF+, Y → -FX-Y. Lévy C-curve (1938): pure recursion, 45° turns, rule F → +F--F+. Visually: Heighway is more “linear/serpentine”; Lévy is more “curled and overlap-heavy” – its self-overlap is the distinctive feature.

What does “self-overlap” mean here?

The Lévy curve passes through the same 2D points multiple times. Unlike the Hilbert curve (which is self-avoiding – no two distinct curve parameters map to the same 2D point), Lévy’s curve visits some points twice or more in the limit. Mathematically: a measure-preserving but NOT one-to-one map from [0,1] to its 2D image. Practically: when you draw at high iter you see darker regions where the curve doubles back. Useful for understanding the difference between “space-filling” (covers a region) and “self-avoiding” (visits each point once).

Why does the curve look “C-shaped”?

At iter 6-10, the overall envelope of the curve has a distinctive C shape with the opening facing one direction. This is the FIRST-iteration U-fold compounded by all subsequent foldings. Earlier iterations: iter 1 is `+F–F+` which traces a 135° wedge (one V); iter 2 is two V’s at 45°; iter 3 starts to curl. By iter 6 you see the recognizable C. Higher iter (12+) fills in the C shape until you can no longer see the C – it becomes a solid blob.

What does gradient mode reveal?

Color lerps from primary (start) to secondary (end) along the traversal order. Useful to see WHICH PART of the curve is drawn first. You’ll notice that adjacent regions in 2D may have very different colors (drawn far apart in time), and 1D-adjacent segments (similar colors) are usually close in 2D. This visualises locality preservation – though for Lévy it’s WORSE than Hilbert because of the self-overlap.

What does segmented mode show?

Alternates primary/secondary per segment (even/odd index). Useful to see SELF-SIMILARITY: the recursive structure means each iter creates pairs of sub-curves rotated 45° – segmented mode highlights the pair structure visually. Try iter 8-10 with high-contrast colors (e.g. blue + orange) – you’ll see the recursive pair-grouping at every scale.

Why does iter 14 take a moment?

Iter N = 2^N segments. Iter 14 = 16,384 segments. Each is a separate Canvas lineTo call. At ~16k operations + path stroke, render takes 100-500 ms. Iter 15 would be 32k (2× wait). Iter 14 is the comfortable ceiling. The L-system string at iter 14 is ~100k characters (each F → 6 chars, doubling per iter from base “F”).

Is my data secure?

Yes – 100% client-side. L-system expansion and Canvas drawing run in your browser. No parameters or images leave your device. Verify via your browser’s Network tab.