Langton's AntBeta
Watch simple ant rules turn chaos into highways and multi-color turmite patterns
This tool is a beta version still being stabilized. Please let us know if a result looks off.
An ant looks at the color of its cell and turns by the matching letter of the rule (L = left, R = right, N = straight, U = U-turn), then shifts the cell to the next color and moves forward. The classic RL rule wanders chaotically for about 10,000 steps before building a 104-step periodic 'highway'. Tap the canvas to add an ant there; the grid wraps around at its edges.
Working…
0.0
It hasn't frozen — the result will appear when the calculation finishes.
About Langton's Ant
Langton's ant is a machine with two rules. On a white cell, turn 90° right; on a black cell, turn 90° left. Then flip the colour of the cell you were standing on and step forward one cell. Christopher Langton introduced it in 1986 in his work on artificial life. The default rule here, “RL”, is exactly that: each letter belongs to one colour, so colour 0 (white) means R and colour 1 means L.
Reset places one ant in the middle of a 256×256 grid, facing up. The edges wrap around to the opposite side, so the ant never falls off. The speed slider sets how many steps are computed per displayed frame; the default of 100 at 60 frames per second works out to about 6,000 steps a second.
What to watch 1: the highway after the chaos
For the first few hundred steps the ant draws small, nearly symmetric shapes, then the picture turns into an irregular, growing blob. That phase lasts about 10,000 steps. Then, abruptly, the ant settles into a 104-step cycle that repeats forever and lays down a straight diagonal strip, the “highway”. At default speed you reach it in a little over two seconds.
On the highway the ant moves 2 cells across and 2 cells along every 104 steps, which is 52 steps per diagonal cell. The tool's own test checks exactly this: after 11,000 steps, 104 further steps must shift the ant by (±2, ±2).
Why the highway appears, and whether it appears from every starting pattern, is still unproven. What is proven is weaker: on an infinite plane, starting from any finite pattern, the ant's path is unbounded; it never stays trapped in a finite region.
What to watch 2: the highway meeting itself on a torus
On an infinite plane the highway would never stop. This grid is a finite doughnut, so the highway runs off one edge, reappears on the opposite side and eventually hits the old chaotic blob or its own trail. The regular motion breaks and chaos resumes; sometimes a new highway later forms in another direction.
A rough estimate: on a 256-cell grid the highway has to travel close to 200 cells in each direction to wrap round into the blob, and at 52 steps per cell that is another 10,000 steps or so. So the collision tends to happen around step 20,000, earlier or later depending on the blob's size. Pick 1024² and the highway survives several times longer.
What to watch 3: rules with more colours
The length of the rule string is the number of colours. On a cell of colour i the ant turns according to letter i, then advances that cell to colour i+1 (wrapping back to 0 after the last). L is left, R is right, N is no turn and U is a U-turn; up to 32 colours are allowed.
- RLR: tends to keep growing chaotically without ever building a highway.
- LLRR: a four-colour rule; compare how its shape grows with RL.
- Long rules such as LRRRRRLLR or RRLLLRLLLRRR: some fill out geometric shapes like triangles and squares instead of blobs.
- Rules with N or U: going straight or reversing changes the character completely, because the ant no longer always turns a corner.
Several ants at once
Tap the canvas to drop an ant there facing a random direction (up to 256 ants). In each generation the ants move one step each, in order, on the same grid, so a cell flipped by one ant is immediately read by the next. Even two ants often erase each other's work and delay or prevent the highway.
The readout shows generations and moves separately. With 10 ants, each generation contains 10 moves, so the move count grows ten times as fast as the generation count (ants added mid-run count from the moment they appear). The speed slider budgets total ant moves per frame, so adding ants makes generations tick up more slowly.
Turing completeness
In a 2002 paper, Gajardo, Moreira and Goles showed that the trajectory of a single ant can evaluate any Boolean circuit, given a suitably prepared initial pattern of cells. So a rule that looks trivial on a blank grid becomes a computer when the grid is pre-drawn. This tool always starts from a blank grid, so you cannot build such a circuit in it.
Worked examples
The first two steps
- Input
RL, blank grid, ant at (100,100) facing up- Output
Ant at (101,100) facing right; (100,100) is now black
White cell: turn right, paint it, move. The next cell is white too, so the ant then turns right again, facing down.
Highway speed
- Input
RL, after about 10,000 steps- Output
(±2, ±2) every 104 steps
52 steps per diagonal cell; covering 1,000 cells would take about 52,000 steps.
Real moves with several ants
- Input
5 ants from the start, 12,000 generations- Output
60,000 moves
Every ant moves once per generation; the “moves” readout accumulates exactly this product.
How to use it
- Pick a preset or type a rule made of L, R, N and U (2 to 32 letters).
- Set steps per frame with the speed slider.
- Tap to add ants; Reset returns to a blank grid with a single ant.
Frequently asked questions
Why does the highway only show up after about 10,000 steps?
It is an observed fact without a known mathematical explanation. From a blank grid the run is deterministic, so here it appears at the same step every time.
The highway collapses part-way. Is that a bug?
No. The edges wrap, so the highway comes round and crashes into the existing pattern. That cannot happen on an infinite plane. A larger grid delays it.
Is the result the same every time I reset?
Yes for a single ant on a blank grid: the rule has no randomness. Ants you add by tapping face a random direction, so those runs differ.
What is Langton's ant used for?
It is a standard example of simple rules producing behaviour that is hard to predict, and a subject in computability research; a single ant can compute Boolean circuits.
Related guides
Sources
- C. G. Langton, Studying artificial life with cellular automata, Physica D 22(1–3), 120–149 (1986)
- A. Gajardo, A. Moreira, E. Goles, Complexity of Langton's ant, Discrete Applied Mathematics 117, 41–50 (2002)
- Wikipedia — Langton's ant (highway, extension to multiple colours)
Last reviewed: