Geometry

The Barnsley Fern: A Living Fractal From Four Rules

The Barnsley Fern is a fractal that looks uncannily like a real black spleenwort, yet it is built from just four simple rules. Each rule is an affine map — a stretch, tilt, and shift of the plane — and you grow the picture by starting at one point and, over and over, picking one of the four maps at random (with fixed odds 0.85, 0.07, 0.07, 0.01) and moving the point. Plot every place the wandering point lands and a lifelike frond appears. The astonishing part: the entire plant is encoded by a recipe of only 24 numbers, the idea that launched fractal image compression.
  • IntroducedMichael Barnsley, 1988 (Fractals Everywhere)
  • ConstructionIterated function system of 4 affine maps
  • Selection probabilities0.85 / 0.07 / 0.07 / 0.01
  • Data to encode24 coefficients (28 with probabilities)
  • Dominant mapscale ≈ 0.85, tilt ≈ 2.7° per copy
  • Fractal dimensionself-affine, ~1.7 (box-counting estimate)

Interactive visualization

Press play, or step through manually. The visualization is yours to drive — try it before reading on.

Open visualization fullscreen ↗

Watch the 60-second explainer

A condensed visual walkthrough — narrated, captioned, under a minute.

An iterated function system: the whole plant in 24 numbers

The fern is an example of an iterated function system (IFS): a small finite list of contraction maps that you apply, over and over, to points of the plane. Each of Barnsley's four maps is affine, meaning it acts by a 2×2 matrix followed by a shift:

w(x, y) = (a·x + b·y + e,   c·x + d·y + f).

The matrix part [[a, b], [c, d]] stretches, shears, rotates, or reflects; the vector (e, f) slides the result somewhere else. So one affine map is pinned down by exactly six numbers. Four maps therefore need 4 × 6 = 24 numbers — and those 24 numbers are the entire genetic code of the fern. (Add the four selection probabilities and you have 28 numbers for a fully renderable recipe.)

The table above lists the canonical values from Barnsley's 1988 book Fractals Everywhere. There is nothing biological hidden inside; every leaf, midrib, and curl emerges purely from iterating these four linear rules. That a photorealistic organism can be squeezed into two dozen coefficients is the whole point, and it is why the fern became the poster child for the idea that fractals compress information.

The four rules, read one at a time

Each map is responsible for one recognizable piece of the plant, and the fern equals the union of its own four transformed copies:

F = w₁(F) ∪ w₂(F) ∪ w₃(F) ∪ w₄(F).

This equation is the definition of self-similarity: the fern is literally made of four smaller ferns.

  • w₁ — the stem. Its matrix [[0, 0], [0, 0.16]] sends every x to 0 and squashes y by a factor of 0.16. Its determinant is 0, so it collapses the two-dimensional plane onto a one-dimensional line segment — the thin vertical stalk. It is a degenerate map, and it is the only one that is.
  • w₂ — the main frond. The dominant map. Its matrix [[0.85, 0.04], [−0.04, 0.85]] is a scaled rotation: it shrinks by a factor of √(0.85² + 0.04²) ≈ 0.851 and rotates by about 2.7°, then shifts up by 1.60. Applied to the whole fern it produces the next-smaller fern, sitting slightly higher and slightly tilted. Iterate w₂ alone and you march up the central axis, each frond a touch smaller and more rotated than the last — that compounding tilt is exactly why the fern curls.
  • w₃ and w₄ — the bottom leaflets. Each shrinks the entire fern to roughly a third (contraction factors ≈ 0.34 and ≈ 0.37), rotates it hard, and drops it into place as a lower side-frond. Map w₄ has negative determinant (−0.109), so it also reflects — the right leaflet is a mirror image, which is why the two sides of the fern are not identical.

Because each leaflet is a shrunken copy of the whole fern, every leaflet is itself a tiny fern, whose leaflets are tinier ferns, forever. That is the fractal, endlessly nested structure you see when you zoom in.

Why it converges at all: Hutchinson's theorem

Why should hammering four maps on a point produce any definite shape, rather than a spreading mess? The answer is one of the cleanest results in fractal geometry, due to John Hutchinson (1981), and it rests on the Banach fixed-point theorem.

First, all four maps are contractions: each shrinks distances by a fixed factor less than 1. The largest such factor here is w₂'s ≈ 0.851 (the others are ≈ 0.16, ≈ 0.34, ≈ 0.38), so the overall contractivity is s ≈ 0.851 < 1. Now bundle the four maps into a single operator that acts not on points but on whole shapes — the Hutchinson operator:

W(S) = w₁(S) ∪ w₂(S) ∪ w₃(S) ∪ w₄(S).

Take the space of all non-empty compact subsets of the plane, measure the distance between two such sets with the Hausdorff metric (how far you must fatten each to swallow the other), and this space turns out to be complete. On it, W is itself a contraction with the same factor s ≈ 0.851. Banach's theorem then hands you the whole story: W has a unique fixed set A with W(A) = A, and starting from any compact set S₀ — a dot, a square, a photograph — the iterates W(S₀), W(W(S₀)), … converge in Hausdorff distance to A. That unique invariant set A is the fern. It exists, it is one-of-a-kind, and it does not depend on where you start. This is the deterministic algorithm for drawing the fern.

The chaos game: randomness that draws a fixed picture

Iterating whole shapes is expensive. Barnsley's practical trick — the random iteration algorithm, popularly the chaos game — moves a single point instead. Start anywhere, say the origin. At each step pick a map at random using the fixed probabilities (0.85, 0.07, 0.07, 0.01), apply it to the current point, plot the result, and repeat tens of thousands of times (discarding the first dozen points, which are still homing in). The scatter of plotted points fills in the fern.

Two facts make this rigorous, and they are worth separating carefully:

  • Which set appears is fixed, not random. The orbit of the point is drawn irresistibly onto the attractor A — the same A guaranteed by Hutchinson's theorem — no matter which random choices occur or where you begin. Run it a million times and you get the same fern.
  • The probabilities set the shading, not the shape. The sequence of points is a Markov chain on the plane, and by Elton's ergodic theorem (1987) it has a unique invariant probability measure μ, supported on A. The long-run fraction of points that land in any region converges (almost surely, from any start) to that region's μ-measure. The probabilities steer μ — the density of dots — but never the set A itself.

How were the probabilities chosen? Roughly in proportion to how much area each map covers, i.e. to |det| of its matrix (about 0.72, 0.10, 0.11 for w₂, w₃, w₄). That balances the fill so no region is starved or over-drawn. The stem map w₁ has determinant 0, so an area-proportional rule would pick it essentially never; it is given a small floor of 0.01 so the stalk still gets drawn.

Self-affine, not self-similar: the dimension question

The Koch snowflake is built from exact scaled copies (pure similarities), so its dimension is given by the clean Moran formula ∑ rᵢᴰ = 1, which for N copies at a single ratio r reduces to D = log N / log(1/r). It is tempting to plug the fern in the same way — but the fern's maps are affine with shear and anisotropic scaling (different stretch in different directions). They are not similarities, and the copies overlap. So the tidy formula does not apply. The fern is a self-affine set, and self-affine sets are genuinely harder.

For such sets, the relevant theory is Falconer's affinity (singular-value) dimension, which gives the dimension for generic affine systems but need not equal the exact Hausdorff dimension for a specific one — and the fern's exact Hausdorff dimension is not known in closed form. Empirically, box-counting estimates put it near ~1.7 — strictly between 1 and 2. That number matches intuition: the fern is far denser than a smooth curve (dimension 1) because its leaflets pack space, yet it has zero area (2-D Lebesgue measure 0), because it is still a thin, nowhere-solid dust of points. Being caught between a curve and a region — with length infinite and area zero — is the signature of a fractal, and the fern wears it.

From 28 numbers to a photograph: the Collage Theorem and compression

Barnsley's deeper goal was inverse: not "here are four maps, what do they draw?" but "here is a real fern photograph, what four maps draw it?" The engine for that is his Collage Theorem. If you can find maps whose union W(L) = ⋃ wᵢ(L) covers a target image L closely, then the IFS attractor A is close to L too, with a guaranteed bound:

dH(L, A) ≤ (1 / (1 − s)) · dH(L, W(L)),

where s is the contraction factor and dH the Hausdorff distance. In words: make a good collage of the picture out of shrunken copies of itself, and the fractal you get back is guaranteed to resemble the picture. Encoding then means storing only the maps — a few dozen numbers — instead of millions of pixels, and decoding means running the chaos game. This is the seed of fractal image compression, developed into practical form with Arnaud Jacquin around 1990 using partitioned IFS (local maps from image blocks to smaller blocks).

In practice fractal compression never displaced JPEG for general photographs — finding good maps is slow, and the wins are largest for images that are actually self-similar. But the fern remains the perfect proof of concept: a lifelike plant, resolution-independent (zoom in and new detail keeps appearing, because the recipe has no smallest scale), reconstructed from 28 numbers. Barnsley's fern modeled the black spleenwort Asplenium adiantum-nigrum, and it turned a slogan — that nature's complexity can hide simple recursive rules — into something you can watch draw itself.

The four affine maps of the Barnsley fern, each of the form w(x,y) = (a·x + b·y + e, c·x + d·y + f)
Map / role(a, b, c, d, e, f)prob pgeometric effect
w₁ — stem(0, 0, 0, 0.16, 0, 0)0.01Collapses the plane onto the vertical stalk; det = 0 (2-D → 1-D)
w₂ — main frond(0.85, 0.04, −0.04, 0.85, 0, 1.60)0.85Scale ≈ 0.85, tilt ≈ 2.7°, shift up: the next smaller copy of the whole fern
w₃ — left leaflet(0.20, −0.26, 0.23, 0.22, 0, 1.60)0.07Scale ≈ 0.34, rotate and place the largest bottom-left frond
w₄ — right leaflet(−0.15, 0.28, 0.26, 0.24, 0, 0.44)0.07Scale ≈ 0.37, reflect (det < 0) and place the largest bottom-right frond

Frequently asked questions

If the maps are chosen randomly, why is it the same fern every time?

Because the shape is determined by the maps, not by the random choices. Hutchinson's theorem guarantees the four contractions have a single unique attractor, and the wandering point is pulled onto that attractor regardless of which maps come up or where you start. Randomness only decides the order in which points fill it in — it never changes the fern that appears.

Do the four probabilities change the fern's shape?

No. The attractor set is fixed by the maps alone. The probabilities determine the invariant measure — how densely each part of the fern gets sampled — so they affect the shading and how fast the image fills in, not the outline. Change them and you get the same fern, just with different local point density.

Why does the stem map get such a tiny probability, 0.01?

That map has determinant 0: it collapses the plane onto a line, so it contributes essentially no area. Since the other probabilities are set roughly proportional to how much area each map covers, an area rule would almost never pick the stem. It is given a small floor of 0.01 so the vertical stalk still gets drawn instead of being starved of points.

Is the Barnsley fern truly self-similar?

It is self-affine rather than strictly self-similar. Self-similar sets like the Koch curve are made of exact scaled-and-rotated copies; the fern's maps also shear and stretch unevenly, and one even reflects, so the copies are distorted versions of the whole rather than perfect miniatures. It still satisfies F = w₁(F) ∪ w₂(F) ∪ w₃(F) ∪ w₄(F), so it is a union of transformed copies of itself — just affine ones.

What is the fractal dimension of the fern?

Because the fern is self-affine, the clean similarity-dimension formula does not apply and no exact closed form is known. Box-counting estimates place it around ~1.7 — strictly between 1 and 2. That reflects a set far denser than a curve yet of zero area: a thin dust of points that nonetheless packs the plane densely along the fronds.

What did Barnsley actually invent this for?

For image compression. His Collage Theorem shows that if shrunken copies of an image can be arranged to cover it, the resulting fractal attractor closely matches the image — so you can store a picture as a handful of map coefficients instead of pixels. The fern is the showcase: a realistic plant, infinitely zoomable, reconstructed from just 28 numbers.