Fractals & L-Systems

Philosophy

Fractals embody self-similarity — the idea that the same structure repeats at every scale, from coastlines to blood vessels to galaxies. Benoit Mandelbrot’s 1982 The Fractal Geometry of Nature argued that classical geometry fails to describe the natural world, and that fractional dimensions reveal a hidden order in apparent chaos.

L-systems (Lindenmayer systems) formalize growth as rewriting. Aristid Lindenmayer created them in 1968 to model plant development. A simple string-rewriting grammar produces startlingly lifelike branching structures — encoding the idea that complexity in nature emerges from recursive application of simple rules.

Key Algorithms

Mandelbrot Set

For each point c in the complex plane, iterate z = z² + c starting from z = 0. Color based on escape iteration count. Points that never escape are “in” the set.

z(n+1) = z(n)² + c
escape when |z| > 2

Parameters: center (real, imag), zoom, max iterations, color mapping

Julia Sets

Same iteration z = z² + c, but c is fixed and you vary the starting z across the plane. Each value of c produces a different Julia set — connected when c is in the Mandelbrot set, dust-like when outside.

Parameters: c_real, c_imag, zoom, max iterations

L-Systems

A grammar: alphabet, axiom (start string), production rules. Interpret the final string as turtle graphics commands.

Classic rules:

Parameters: axiom, rules, angle, iterations, segment length, randomness

Barnsley Fern (IFS)

Four affine transformations applied randomly with weighted probability. Each maps a point to a new point; over millions of iterations, a fern emerges.

Parameters: transformation coefficients, probability weights

Notable Artists & Works

p5.js Implementation Notes

nannou Implementation Notes

Space-Colonization / Organic Growth

MacTuitui’s tree.rs (in nannou’s examples/offline/) demonstrates a sophisticated growth pattern useful for generative trees, corals, roots, and neural networks:

This produces organic, asymmetric branching structures — far more natural-looking than pure recursive L-systems. Combine with per-generation color mapping for depth visualization.

SDF-Based Fractals (2D)

Signed distance fields offer an alternative approach to 2D fractal construction. Instead of iterating complex numbers or rewriting strings, build fractal-like forms by composing SDF primitives with domain operations:

// Sierpinski-like 2D fractal via domain folding
float fractalSDF(vec2 p, int iterations) {
  float scale = 1.0;
  for (int i = 0; i < iterations; i++) {
    p = abs(p) - 0.5;           // fold (mirror at ±0.5)
    p *= mat2(0.866, -0.5, 0.5, 0.866); // rotate 30°
    scale *= 2.0;
  }
  return sdBox(p, vec2(0.5)) / scale;
}

See references/sdf-2d.md for 2D SDF primitives and boolean operators, and references/shaders-glsl.md for 3D SDF fractals (Mandelbulb, Menger sponge).

Perceptual Coloring for Fractals

Classic Mandelbrot/Julia coloring maps iteration count to a palette. Using perceptual color spaces dramatically improves the result:

Demos in the gallery

IFS Attractor
Iterated Function System — a set of contractive affine maps repeatedly applied to a starting point. The trajectory's accumulation forms the system's attractor: ferns, dragons, koch curves, and other self-similar fractals from a few coefficients.
Julia Set
The Julia set for a chosen complex constant c — connected when c is in the Mandelbrot set, dust-like when outside. Sweeping c traces a continuous family of intricate fractals, each a 'snapshot' of the Mandelbrot's local structure.
L-System Tree
Aristid Lindenmayer's 1968 grammar — a string rewritten by production rules, then interpreted as turtle-graphics commands. Iteratively expands a single 'F' into a fractal tree, plant, or weed via biologically-inspired branching rules.
Mandelbrot Set
The classical Mandelbrot set — escape-time iteration of z² + c in the complex plane. Boundary points exhibit infinite self-similar detail; the famous 'sea horse valley' and 'elephant valley' live in the recursive cardioid attachments.
Mandelbulb Explorer
A volumetric extension of the Mandelbrot set — escape-time iteration in 3D. Raymarched per-pixel using an analytic distance estimator. Tweak the fractal power and orbit the camera to find new structures.
Menger Sponge
Karl Menger's 1926 fractal — a cube with its 20 corner sub-cubes removed at every scale. The limit shape has zero volume but infinite surface area. Raymarched via iterated SDF folding.
Quaternion Julia
The Julia set extended to four-dimensional quaternion arithmetic, then sliced into 3D for visualization. Different choices of the constant c yield wildly different organic 3D forms — from coral-like branchings to droplet structures.
Sierpinski Tetrahedron
Wacław Sierpiński's 3D fractal — a tetrahedron recursively replaced by four smaller tetrahedra at its corners. The limit shape has self-similar structure at every scale; each visible 'gap' is its own missing tetrahedron.