← Math

🌿 2D Barnsley Fern

Written by MySimulator Team · Reviewed by MySimulator Editorial Review

Last updated: 13 September 2026

Speed: 2000/f
Points plotted: 0  |  Iterations: 0  |  Transforms used: f1 0 f2 0 f3 0 f4 0

🌿 2D Barnsley Fern — Chaos Game IFS

The real Barnsley fern: four affine transformations, chosen randomly at probabilities 0.01/0.85/0.07/0.07, iterated point-by-point directly on a flat 2D canvas via the Chaos Game algorithm. Edit the coefficients and probabilities live and watch the exact same math distort the fern into new shapes.

🔬 What It Demonstrates

Each of the four transforms follows xₙ₊₁ = a·xₙ + b·yₙ + e and yₙ₊₁ = c·xₙ + d·yₙ + f. One transform is picked at random each iteration, weighted by its probability, and the resulting point is plotted immediately — there is no pre-rendered image, only a running random walk that converges onto the fern attractor.

🎮 How to Use

Watch the fern accumulate point by point. Use Speed to control how many iterations run per frame, Pause/Resume to freeze the walk, and Coefficients to open the full a,b,c,d,e,f and probability editor for all four transforms — press Apply & Restart to see your custom IFS grow from scratch.

💡 Did You Know?

Michael Barnsley developed IFS theory in 1988 while working on image compression. The fern fits in just 24 numbers — the a,b,c,d,e,f coefficients of four affine maps — yet expands into an infinitely detailed self-similar shape of fractal dimension ≈ 1.74.

About the 2D Barnsley Fern — Chaos Game Simulation

This simulation runs the real Barnsley fern Iterated Function System directly on a 2D canvas using the Chaos Game algorithm. Starting from the origin, one of four affine transformations is chosen at random each iteration — with probabilities of 1%, 85%, 7%, and 7% — and the resulting point is plotted immediately as a single pixel. There is no pre-computed image: every frame genuinely advances the random walk, and the recognisable fern shape emerges from the accumulating cloud of points.

Unlike a static rendering, every one of the twenty-four coefficients (a, b, c, d, e, f for each of the four transforms) plus their four probabilities is exposed and editable. Changing a coefficient and restarting shows exactly how that number reshapes the attractor — for example, increasing the probability of the "stem" transform thins out the frond, or changing the rotation terms (b, c) skews the leaflets.

Frequently Asked Questions

How is this different from the 3D Barnsley Fern simulation?

The 3D version extrudes each chaos-game point along a z-axis and renders the resulting point cloud with WebGL so it can be orbited and zoomed. This 2D version keeps every point in the original x-y plane, drawn directly with the browser's 2D canvas API — there is no depth, no camera, and no WebGL. Instead, this version exposes and lets you edit the raw a,b,c,d,e,f coefficients and probabilities of all four transforms directly, which the 3D version does not.

What happens if I edit the coefficients?

Each transform is an affine map xₙ₊₁ = a·xₙ + b·yₙ + e, yₙ₊₁ = c·xₙ + d·yₙ + f. Changing a or d scales the transform along x or y; b and c introduce shear/rotation; e and f translate it. Because the fern is the attractor of these four contractions applied together, even a small change to one coefficient reshapes the whole leaf once you press Apply & Restart.

Why does the fern take a moment to fully appear?

The Chaos Game is a random walk: each new point depends on the previous one and a randomly chosen transform. The shape only becomes recognisable once enough points have accumulated — this is genuinely how the algorithm works, and the simulation's Speed slider controls how many iterations are computed per animation frame so you can watch it converge at your own pace.

What are the exact default affine transformation coefficients?

Each transform follows xₙ₊₁ = a·xₙ + b·yₙ + e and yₙ₊₁ = c·xₙ + d·yₙ + f. The classic fern uses: f1 [a=0, b=0, c=0, d=0.16, e=0, f=0, p=0.01] for the stem; f2 [a=0.85, b=0.04, c=-0.04, d=0.85, e=0, f=1.6, p=0.85] for the main blade; f3 [a=0.2, b=-0.26, c=0.23, d=0.22, e=0, f=1.6, p=0.07] for the left leaflet; and f4 [a=-0.15, b=0.28, c=0.26, d=0.24, e=0, f=0.44, p=0.07] for the right leaflet.

What is the Chaos Game algorithm?

The Chaos Game is a probabilistic algorithm introduced by Michael Barnsley in his 1988 book "Fractals Everywhere." Rather than computing the attractor analytically, you pick a random starting point and repeatedly apply a randomly chosen contraction map, weighted by probability. For almost every starting point, the orbit eventually traces the exact attractor — which is exactly what this simulation renders live, point by point, on the 2D canvas.

What is the fractal dimension of the Barnsley Fern?

The Barnsley Fern has a Hausdorff fractal dimension of approximately 1.74, lying between 1 (a line) and 2 (a filled plane). This reflects that the fern is a complex self-similar curve that partly fills the plane but is not dense in any 2D region, a property that holds regardless of whether the attractor is rendered flat in 2D or extruded into 3D.

Can I break the fern shape by editing the coefficients?

Yes — that is the point of exposing the real math. Setting a probability to zero removes that branch entirely (for example, zeroing f3's probability removes the left leaflet). Extreme coefficient values can also push the iteration outside the stable contraction range, in which case the simulation resets the point to the origin and continues, rather than producing NaN pixels.