1618.dev

small tools, one committed a day

Barnsley Fern Generator

This fern isn't drawn pixel by pixel — it's played as a game. Start at a point, then repeatedly roll a die and jump according to one of four affine maps (each picked with its own probability), plotting every landing. The scattered dots converge onto one fixed shape, the maps' attractor — a fern. It's the cleanest example of an Iterated Function System (IFS). Edit the numbers below and watch the fern mutate.

points zoom

Watch it draw itself · scroll to zoom · drag to pan. Each preset and every edit replays the chaos game from scratch.

The four maps — edit to mutate

Each row is one affine map x′ = a·x + b·y + e, y′ = c·x + d·y + f, chosen with probability p. Nudge any value and the fern redraws. (Probabilities are renormalised to sum to 1.)

mapabcdefp

Geometry of each map

What each map actually does to the plane — its scale (largest and smallest stretch), rotation, and area factor (the determinant). Computed in logic.py. Every map shrinks (largest scale < 1); that contraction is exactly why the chaos game settles onto a finite fern instead of flying apart.

mappscale (max × min)rotationarea ×role

What an Iterated Function System is

An IFS is just a small set of contraction maps — transforms that move points closer together. A deep theorem (Hutchinson, 1981) guarantees any such set has exactly one attractor: a unique shape that is the union of shrunken copies of itself under the maps. The fern is the attractor of these four. Because each map contracts, fine detail keeps nesting inside coarse detail — that self-similarity is the fractal.

Why the chaos game works

You'd think jumping at random would give noise. It doesn't, for a subtle reason: every map drags points toward the attractor, so after a few jumps your point is effectively on the fern and stays there forever after, wherever you started. Each plotted dot is a real point of the attractor. The probabilities only control density — set roughly proportional to each piece's area so the dots spread evenly rather than piling up.

What the four maps do

How this page is built

The math lives in logic.py — the affine maps, the chaos-game step, the probability selection, and the geometric decomposition of each map. The fern is plotted in JavaScript (hundreds of thousands of points, animated so you can watch it form), but the same Python computes the geometry table above, so those numbers come straight from the source of truth.