The chaos game explained
The chaos game is the most surprising way to draw a fractal. Its rule fits in one sentence, it uses nothing but a die, and every move is random, yet the result is always the same intricate shape, sharp down to the last pixel. Behind it lies one of the central ideas of fractal geometry: a fractal as the one shape that a few shrinking maps leave unchanged.
The rules of the game
Mark three points, the corners of a triangle, and number them 1 to 6 in pairs, so that a die picks one of them. Put your pencil anywhere. Roll the die, move halfway from the pencil towards the corner it picked, and make a mark there. Roll again, move halfway towards the new corner, mark again. That is all. The first few marks look like nothing in particular, but after a few hundred a pattern of triangles within triangles appears, and after a few thousand it is unmistakably the Sierpiński triangle.
Why chance draws a fixed shape
Moving halfway towards a corner is a map that shrinks the whole plane by half towards that corner. The Sierpiński triangle consists of exactly three half-size copies of itself, one at each corner, so each of the three maps sends the triangle onto a part of itself. A mark that lies on the triangle therefore stays on it, whatever the die says. A mark that does not lie on it halves its distance to the triangle with every move, so after ten moves it is a thousand times closer than it started and indistinguishable from a point of the triangle. The die only decides which parts get filled in first.
Iterated function systems
Michael Barnsley gave the game its name in his 1988 book Fractals Everywhere, as a way to draw iterated function systems: a handful of maps, each of which shrinks the plane. John Hutchinson had shown in 1981 that every such system has exactly one attractor, the shape that equals the union of its own images under the maps. The chaos game finds the attractor by applying the maps at random; drawing all the images over and over is the other way. With the right maps the attractor is a fern, a tree or a cloud, which is how Barnsley's famous fern is drawn.
Other targets, other fractals
The targets need not be three corners. The four corners and four edge midpoints of a square with a jump of 2/3 give the Sierpiński carpet, eight copies at a third of the size. The four corners and the centre give the Vicsek fractal, a cross of crosses. Five corners with a jump of about 0.618, one over the golden ratio, give the pentaflake, where five copies of the whole just touch. Six corners and the centre with a jump of 2/3 give the hexaflake. These n-flakes exist for every polygon; the jump only has to be long enough that the copies do not overlap.
When the copies overlap
Play the game on a square with a jump of one half and nothing interesting happens: the four half-size copies of the square tile it exactly, and the marks fill the square evenly. Play it on a pentagon with a jump of one half and the five copies overlap, so the marks fill a solid region with darker and lighter patches. For a regular polygon the copies stop overlapping when each is scaled by at most a certain ratio: 1/2 for the triangle and the square, about 0.382 for the pentagon, 1/3 for the hexagon. Below that ratio the game draws a fractal.
Restricted games
A rule about which target may follow which brings back the fractals. On a square with a jump of one half, never choosing the same corner twice in a row draws a fractal of linked crosses, and never choosing the corner one step clockwise of the last draws four spiralling arms. On a pentagon, never choosing a corner next to the last one draws a five-pointed star full of smaller pentagons. Such restricted chaos games are graph-directed iterated function systems: the maps that may follow each other form a graph, and the attractor is no longer made of simple copies of itself.
Measuring the dimension
A shape made of N copies of itself, each scaled by s, has the similarity dimension log N / log(1/s), as long as the copies do not overlap: log 3 / log 2 ≈ 1.585 for the Sierpiński triangle, log 8 / log 3 ≈ 1.893 for the carpet, log 5 / log 3 ≈ 1.465 for the Vicsek fractal. For the restricted games there is no such formula, but the dimension can still be measured from the marks. Lay a grid of boxes over the picture and count the boxes that hold a mark; halve the boxes and count again. The count grows as the boxes shrink by a power, and that power is the box-counting dimension.
Explore it
Open the chaos game and press One jump a few times to watch single rolls, with the dashed line to the chosen target and the new mark ringed. Then press Play and let it run at thousands of marks a second. Try the presets, change the corners, the extra targets, the jump and the rule, and drag a target to bend the whole fractal. Colour by copy shows every target's copy of the whole, and the pencil opens the picture in the photo editor with each copy on a layer of its own.
Frequently asked questions
Who invented the chaos game?
The name comes from Michael Barnsley, who described it in his 1988 book Fractals Everywhere as a way to draw the attractors of iterated function systems. The mathematics behind it, that a set of shrinking maps has exactly one attractor, was worked out by John Hutchinson in 1981.
Does the starting point matter?
No. Every jump shrinks the distance to the fractal by the same factor, so within a few dozen jumps the marks lie on the fractal to within less than a pixel. The app skips the first jumps so the starting point does not show.
Does it depend on the random numbers?
The shape does not, as long as every target keeps being chosen. Different random numbers only fill in the shape in a different order. A die that favours some targets fills their copies more densely, which is how Barnsley's fern gets its shading.
Why does a square with a jump of one half not give a fractal?
Because the four half-size copies of a square tile it exactly, with no gaps and no overlaps, so the attractor is the whole filled square. A longer jump, such as 2/3 with the midpoints added, or a rule that forbids some jumps, is needed for a fractal.
What is the dimension of the Sierpiński triangle?
log 3 / log 2 ≈ 1.585. It is made of three copies of itself at half the size, and 2 to the power 1.585 is 3. The chaos game's marks give about 1.56 by box counting with a million marks; finer grids and more marks bring the estimate closer.
Ready to try it?
Open PictorX in your browser — no install, no credit card required to start.
Open the chaos game