# Barnsley Fern

> Drag the slider N from 100 to 10,000 points and watch Barnsley's fern fill in: the chaos game with four affine maps, the frond first, the leaves last.

Michael Barnsley's fern, from his book Fractals Everywhere (1988), is the attractor of four affine maps of the plane: the stem $f_1(x, y) = (0, 0.16y)$, the frond $f_2(x, y) = (0.85x + 0.04y, -0.04x + 0.85y + 1.6)$, the left leaf $f_3(x, y) = (0.2x - 0.26y, 0.23x + 0.22y + 1.6)$ and the right leaf $f_4(x, y) = (-0.15x + 0.28y, 0.26x + 0.24y + 0.44)$. The chaos game draws it: start at $(0, 0)$, and at each step apply one of the maps, chosen at random with the probabilities $0.01$, $0.85$, $0.07$ and $0.07$.

Each point depends on the one before it, so the game is a loop. The document's prelude function plays it once when the document opens, for 10,000 steps, and keeps the points. The choices do not come from a random operator: they come from the Park–Miller generator $s \to 16807\,s \bmod (2^{31} - 1)$, which is exact in double precision, so each open of the document, on every computer, draws the same fern.

The slider $N$ sets how many of the points the plot shows, from 100 to 10,000. A drag from small to large shows the fern fill in: the frond first and the fine leaves last. The fern spans $x$ from about $-2.2$ to $2.7$ and $y$ from 0 to 10.

- [Open the interactive version](https://graph-paper.io/showcase/en/barnsley-fern)
- [Learn more on Wikipedia](https://en.wikipedia.org/wiki/Barnsley_fern)
