loading...
Box counting: log N against log(1/e). Green fit, orange theory
running...
The science
The chaos game is a random walk with a strict rule: start anywhere, pick a vertex at random, jump the fraction 1 - r of the way towards it, plot the point, repeat. Randomness alone would give a blur; the fixed contraction turns it into a precise shape.
x_(n+1) = r x_n + (1 - r) v_i (i chosen at random)
Every jump contracts distances by exactly r, so any two orbits that use the same dice rolls approach each other as d_n = r^n d_0 (third graph). The memory of the start is lost, and what is left is the set of points that can be written as an infinite sum of vertex choices:
x = (1 - r) Σk≥1 r^(k-1) v_(i_k)
That set is the attractor. It is made of n smaller copies of itself, each scaled by r. A shape like that has a similarity dimension s that solves the Moran equation:
n r^s = 1 ⇒ s = ln n / ln(1/r)
For the Sierpinski triangle (n = 3, r = 1/2) this is ln 3 / ln 2 = 1.585: more than a line, less than a filled area. For the tetrahedron (n = 4, r = 1/2) it is exactly 2. When a rule forbids some vertex pairs (for example "never the same vertex twice"), the number of copies is replaced by the spectral radius ρ of the allowed-move matrix A, where Aij = 1 if vertex j may follow vertex i:
ρ(A) r^s = 1 ⇒ s = ln ρ(A) / ln(1/r)
If the formula gives s larger than the space dimension, the copies overlap so much that the points fill the area (or volume) and the true dimension is the space dimension.
Box counting measures dimension without knowing the rule: cover the picture with boxes of side e and count how many contain a point. For a fractal N(e) grows like e^(-D), so the slope of log N against log(1/e) is the dimension D. The page counts boxes on a hit grid (1024 x 1024 in 2D, 128 x 128 x 128 in 3D) and fits only scales where the count is not limited by the number of points.
The Barnsley fern and the Heighway dragon are iterated function systems with affine maps x → Ai x + ti chosen with probabilities pi. Their dimension is not given by the simple formula (the maps are not similarities), so only the measured box-counting value is shown.
Honest simplifications. The first 12 jumps are discarded so the walker has landed on the attractor. Box-counting dimension from a finite sample always reads a little low (here about 1 to 2 percent for the triangle) because the finest boxes are only partly filled. For rules that remove copies the Moran formula assumes the copies do not overlap (the open set condition); the preset "overlap" cases show what happens when they do. The pseudo-random generator is seeded, so a seed reproduces a picture exactly.
Numerical checks on this page (run automatically): (1) 300 000 chaos-game points of the triangle give a box-counting dimension within 4 percent of ln 3 / ln 2; (2) after 40 jumps the point equals the closed-form sum above to 1e-12; (3) the spectral radius of the pentagon "no repeats" matrix is n - 1 = 4.