The Chaos Game, Explained

After reading this you will know why jumping halfway to random corners of a triangle draws the Sierpiński gasket, how to write the update rule for any number of corners, and how small rule changes produce entirely different fractals.

What the chaos game is

The chaos game is a rule for making dots on a plane. You choose a few fixed points called corners. You drop a starting dot anywhere. Then you repeat one step forever: pick a corner at random, move the current dot part of the way toward that corner, and mark the new position. That is the whole recipe.

The startling part is what appears. Take three corners of a triangle and a jump fraction of one half. The dots never scatter into a gray blur. They avoid an intricate set of gaps and settle onto the Sierpiński triangle, a fractal made of three shrunken copies of itself, each copy again made of three, without end. The randomness only decides the order in which dots appear. The set of points they can land on is fixed before you start.

Here is the hook worth holding onto. A random process gives a non-random picture. Roll a die a million times, and the summary picture is exactly the same triangle every run.

When to use it, and when not

Reach for the chaos game when you want to see how an iterated function system builds a fractal. It is the cleanest demonstration that determinism can hide inside randomness. It also shows, in one screen, how sensitive a fractal is to its rules: change the jump fraction from 0.5 to 0.6 with three corners and the gasket grows fatter and overlaps itself.

Do not read it as a model of a physical system. Real ferns do not roll dice to grow, even though a variant of the chaos game draws a fern that looks convincing. The tool is a picture of a mathematical attractor, not a theory of biology. It also does not compute the fractal dimension for you, though you can estimate it from the rules, as shown below.

The chaos game is one of several ways to draw the same set. You could instead repeatedly apply all the corner rules to a whole shape at once. The random walk version wins on memory: it needs only the current point, not a growing list of shapes.

The update rule and why it contracts

Label the corners c_1, c_2, \dots, c_n as fixed points in the plane. Let p_t be the current point at step t. Each step chooses a corner c_i at random and applies:

p_{t+1} = p_t + r\,(c_i - p_t) = (1 - r)\,p_t + r\,c_i

Here r is the jump fraction between 0 and 1. When r = 0.5 you land exactly halfway between the old point and the chosen corner. The term c_i - p_t is the vector pointing from your dot to the corner, and r scales how far along it you travel.

Each corner rule is an affine contraction. It shrinks distances by the factor 1 - r. Check it: pick two points, apply the same rule to both, and the distance between the results is (1 - r) times the original distance. With r = 0.5 every step halves the spread. Because every rule shrinks, the starting point is forgotten fast, and the dots collapse onto a single fixed set called the attractor.

The number of small copies is n, one per corner, each scaled by 1 - r. For a self-similar set the similarity dimension is:

D = \frac{\ln n}{\ln \left( \frac{1}{1-r} \right)}

With n = 3 and r = 0.5 this gives D = \ln 3 / \ln 2 \approx 1.585. The Sierpiński triangle fills more than a line but less than a solid area, which is what a dimension between 1 and 2 means.

A worked example reproducing the demo

The demo uses three corners, jump fraction 0.5, and no repeat restriction. Place the corners at simple coordinates so you can check every number by hand.

Five steps by hand

Corners: c_1 = (0, 0), c_2 = (1, 0), c_3 = (0.5, 0.866). Start at p_0 = (0.2, 0.5). Suppose the random corner choices are 3, 1, 1, 2, 3. Each step uses p_{t+1} = 0.5\,p_t + 0.5\,c_i.

  1. Corner 3: x = 0.5(0.2) + 0.5(0.5) = 0.35, y = 0.5(0.5) + 0.5(0.866) = 0.683. Point (0.35, 0.683).
  2. Corner 1: x = 0.5(0.35) + 0.5(0) = 0.175, y = 0.5(0.683) + 0.5(0) = 0.3415. Point (0.175, 0.3415).
  3. Corner 1: x = 0.0875, y = 0.1708. Point (0.0875, 0.1708).
  4. Corner 2: x = 0.5(0.0875) + 0.5(1) = 0.5438, y = 0.5(0.1708) = 0.0854. Point (0.5438, 0.0854).
  5. Corner 3: x = 0.5(0.5438) + 0.5(0.5) = 0.5219, y = 0.5(0.0854) + 0.5(0.866) = 0.4757. Point (0.5219, 0.4757).

Notice how quickly the starting point stopped mattering. By step 3 the influence of p_0 has been multiplied by 0.5^3 = 0.125. After 20 steps that factor is under one part in a million, so the first dozen dots are usually discarded as "burn-in" to avoid marking points that sit off the attractor.

The triangle outline plus the six points from the worked example. Each dot lands halfway between the previous dot and the chosen corner.

With three corners and jump fraction 0.5 the dots trace the Sierpiński triangle with clear triangular holes. Set the fraction to 0.33 and the copies shrink and pull apart into three disconnected clusters. Set it to 0.66 and the copies overlap into a solid blob with no visible gaps.

Reading the picture

Three features tell you what rule produced an image. First, count the large copies. Three copies means three corners, four copies means four corners, and so on. Second, measure how much smaller each copy is than the whole: that ratio is 1 - r. Third, check whether the copies touch, gap, or overlap. Copies that just touch at points give the sharp classic fractals.

Color coding by the chosen corner adds a fourth reading. In the three-corner gasket every dot in the bottom-left sub-triangle arrived by jumping toward corner 1. So the three colors carve the picture into three regions that are themselves miniature colored gaskets. This is the self-similarity made visible.

Point density matters for what you see. With 2000 dots the gasket looks like scattered specks. With 200000 dots the gaps are crisp and the edges look solid. The dots per second do not change the attractor, only how filled in it looks.

Common mistakes

Do not expect structure from four corners with unrestricted jumps at r = 0.5. Four half-jumps to square corners fill the whole square evenly, giving a gray box and no fractal. You must add a rule, such as forbidding the same corner twice in a row, before a pattern emerges.

A second mistake is forgetting burn-in. If you plot the very first point and it sits far outside the triangle, it stays visible as a stray dot. Discard the first 10 to 20 points and the picture is clean.

A third mistake is misreading the jump fraction. Some people expect a larger r to spread the dots out. It does the opposite in one sense: a larger r pulls each dot closer to the corner it chose, which makes the copies smaller relative to their target but makes them overlap more near the center. Test r = 0.4 against r = 0.6 and compare.

Related tools

The chaos game is one door into fractals and dynamical systems. The Mandelbrot Explorer shows a fractal born from iterating a complex map instead of a random one. The Lorenz Attractor traces a strange attractor in continuous time, another set that random-looking motion is drawn toward. The Logistic Map Bifurcation shows a single number sliding from order into chaos.

For self-similar structure built by different rules, compare Conway's Game of Life and Elementary Cellular Automata, both of which grow complex patterns from simple local updates. The Magnetic Pendulum Fractal shows a fractal appearing from a physical rule rather than a plotting recipe. To watch randomness that does not converge to a fixed shape, try the Random Walk Explorer.

Frequently asked questions

Why does randomness give the same picture every time?

Because every corner rule shrinks distances, the attractor set is fixed by the rules alone. The random choices only decide which parts of that set get visited first and in what order. Run it twice with different random seeds and both runs fill the identical Sierpiński triangle.

Why exactly one half for the triangle?

With three corners you need each of the three shrunken copies to just touch its neighbors without overlapping. A scale factor of 1 - r = 0.5 makes each copy half the size of the whole, and three half-size triangles tile the original with three triangular holes. That touching condition is what makes the gasket sharp.

How do I get the Barnsley fern?

The fern needs four different affine rules, not just jumps to corners, and the rules are chosen with unequal probabilities. One rule is nearly flat and draws the stem, the others rotate and shrink to make the leaflets. The chaos game framework is the same: pick a rule at random, apply it, mark the point.

What does the fractal dimension mean here?

It counts how detail scales. A dimension of 1.585 means that shrinking the ruler by a factor of 2 reveals 3 times as much structure, since 2^{1.585} \approx 3. The set is more than a curve and less than a filled region.

Does the starting point matter?

Almost never. Its effect is multiplied by (1-r)^t each step, so it vanishes fast. The one exception is that an early dot can leave a visible stray mark, which is why you discard the first several points.