Fractal / Recursive Subdivision
First appeared 1975 · Benoit Mandelbrot — Benoit Mandelbrot coined "fractal" (1975); "The Fractal Geometry of Nature", 1982. · timeline ↗
community / folk Name — Descriptive: "fractal" was coined by Benoit Mandelbrot (1975); "fractal recursion" is a descriptive label for recursive self-similar generation, not a coined algorithm name.
In one line A general technique that generates self-similar structure by applying a rule to a shape and then to its parts, repeatedly — Koch curves, the Sierpiński gasket, recursive rectangle splits (Mondrian-like), and branching trees.
The code
The actual sketch behind the demo above — sandboxed and reproducible. This is the whole thing.
fractal-recursion/index.html
const SEED = Math.floor(Math.random()*1e9);
// Recursive subdivision: each square is probabilistically split into 4
// quadrants; leaves are filled with a depth-tinted colour. A self-similar
// Mondrian-meets-quadtree fractal.
function setup() {
randomSeed(SEED);
const s = Math.min(windowWidth, windowHeight);
createCanvas(s, s);
colorMode(HSB, 360, 100, 100);
background(0, 0, 8);
const baseHue = random(360);
subdivide(0, 0, s, 0);
function subdivide(x, y, size, depth) {
const pSplit = Math.max(0, 0.92 - depth * 0.14);
if (size > s * 0.02 && depth < 8 && random() < pSplit) {
const h = size / 2;
subdivide(x, y, h, depth + 1);
subdivide(x + h, y, h, depth + 1);
subdivide(x, y + h, h, depth + 1);
subdivide(x + h, y + h, h, depth + 1);
} else {
const h = (baseHue + depth * 34) % 360;
fill(h, 60, 30 + depth * 9);
stroke(0, 0, 8);
strokeWeight(s * 0.0015);
const g = size * 0.04;
rect(x + g, y + g, size - 2*g, size - 2*g, size * 0.06);
}
}
}How it works
Define a base case and a recursive step that replaces a shape with smaller copies/parts of itself, then call it on each part: 1. If the recursion depth (or smallest size) limit is reached, draw the shape and return. 2. Otherwise transform the shape into N sub-parts (e.g. split a segment into the 4 pieces of the Koch curve; split a rectangle into 2–4 sub-rectangles; spawn child branches at an angle) and recurse into each. Because the same rule runs at every scale, detail appears at all magnifications (self-similarity). The branching factor, scale ratio and any randomness in the split control the look — from rigid Sierpiński triangles to organic trees.
Parameters
depth: number — Maximum recursion depth.splitCount: number — Children produced at each subdivision.ratio: number — Scale factor applied to each child relative to its parent.angle: number — Branching/rotation angle applied per level.
Lineage
Frequently combined with
- Particle System · 4 works
- Geometric / Hexagonal Tiling · 4 works
- Bezier / Catmull-Rom Splines · 3 works
- Symmetric Blob / Rorschach · 2 works
- Polygon Mosaic · 2 works
- Multi-color Modular Truchet · 2 works
- Quadtree / Recursive Quad Split · 2 works
- Boids / Flocking · 2 works
- Raymarching with SDFs · 1 work
- Perlin / Simplex Noise · 1 work
- Plotter-style Hatching · 1 work
- Poisson Disk Sampling · 1 work
Works using this algorithm (25)
References
Last updated 2026-07-16