Skip to content
Adrien Hubert

Chaos game.

Pick a number of vertices. Drop a starting point anywhere. On every step, choose a vertex at random and move the point a fixed fraction of the way toward it. A million steps in, the plot is full of a shape that nobody drew.

0 points
Try

Why a shape appears

With three vertices and a ratio of one half, the system can only reach points whose binary coordinates in a triangular base are finite. Every other point in the triangle is excluded, and what remains is the Sierpinski gasket. Michael Barnsley pinned this idea to the broader theory of iterated function systems in Fractals Everywhere (1988): a fractal as the attractor of a set of contractions, found by following any one of them at random.

What the controls do

Vertices set the polygon. Ratio sets how far the point travels on each step; values around 1/2 give the cleanest figures, and smaller ratios shrink the attractor toward each vertex into isolated dust. The rule restricts which vertex is allowed next, given which one was just used. A square with the rule "not the same vertex" produces a recognisable square Sierpinski variant that the plain rule does not.

Implementation notes

The loop draws 4000 points per frame as single-pixel rectangles with low alpha, so density builds up where the attractor is denser. The vertices are placed on a circle, with the top vertex always pointing up. Resetting clears the canvas and the point counter, then re-renders the vertices as small filled dots so the geometry stays visible against the cloud.