Langton's Ant

Langton's Ant is a two-dimensional Turing machine, a cellular automaton Chris Langton introduced in 1986. Two deterministic turns are enough to grow patterns that look unpredictable, and then, after a long chaotic stretch, a perfectly regular highway.

Langton's Ant after the highway appears, cells coloured by the step that flipped them
Langton's Ant after the highway appears, cells coloured by the step that flipped them

The rules

The ant walks an infinite grid of squares. Each square is white or black, and the ant faces north, east, south or west. The colour under its feet decides the whole next move. On a white square it turns 90° right (clockwise), paints the square black, and steps forward one cell. On a black square it turns 90° left (anticlockwise), paints the square white, and steps forward one cell. There is no randomness. Run the same start twice and you get the same picture.

Three phases

Start the ant on an empty white grid and its behaviour falls into three familiar stretches. 1. Simplicity and symmetry, from step 1 to about step 500. The trail is small and often symmetric. 2. Chaos, from about step 500 to about step 10,000. The ant is caught in its own path. The picture looks like noise, even though every step is fixed in advance. 3. The highway, after about 10,000 steps. The ant locks into a cycle of 104 steps. Each cycle adds a repeating diagonal block and shifts the ant two cells sideways and two cells forward. Once that cycle starts in open grid, it continues forever, and the ant builds a straight highway out of the chaos.

Why it matters

The ant is one of the clearest demonstrations of emergence: complicated, hard-to-predict structure from a handful of local rules. It is also Turing-complete. With a suitable starting pattern, the same kind of rule can carry out any computation a general-purpose computer can. You do not need that machinery to enjoy the picture. The highway is already the surprise.

Colours, colonies, hexes and turmites

The idea has been extended in several directions. Multi-colour rules replace black and white with a list of turns, written as a string of L and R. RL is the classic ant. RLR, LLRR and LRRRRRLLR give each colour its own turn. The ant writes the next colour in the list, and some of these rules grow symmetric geometric figures instead of a single highway. Several ants share one grid. When their trails meet they can cut a highway apart or weave a pattern neither ant would build alone. A hexagonal grid gives the ant six directions. A right or left turn is then 60° instead of 90°. A turmite keeps an internal state, a small memory. The turn and the colour it writes depend on both the cell and that state, so the rule itself changes as the ant walks. Spiral, Weave and Drift in the app are two-state, two-colour turmites.

Explore it in PictorX

Open Langton's Ant to run the classic ant, jump into the chaotic phase, or start on the highway. Type a turn rule, add ants, switch the grid to hexagons, or pick a turmite. Drag to pan, scroll to zoom, paint cells and drop extra ants. Save a PNG or open the canvas in the PictorX editor. Pair it with the Collatz Conjecture or Reaction-Diffusion Lab for more simple rules with surprising pictures.

Frequently asked questions

Who invented Langton's Ant?

Chris Langton, in 1986. It is a two-dimensional Turing machine: one ant, an infinite grid, and a turn that depends only on the colour of the current cell.

Does every starting pattern build a highway?

The empty grid does, after about 10,000 steps, and the 104-step cycle continues once the ant is on that highway. Other starting patterns and other rules can build highways, stay bounded, or grow in a different shape. The app's Highway favourite places the classic ant just after the cycle begins.

What does the rule string mean?

Each character is the turn for one colour. R means turn right, L means turn left. After the turn, the ant advances the cell to the next colour and steps forward. RL is black and white. A longer string is a multi-colour ant.

How is a turmite different from the ant?

The classic ant has no memory beyond the grid. A turmite also has an internal state. The cell colour and that state together choose the write colour, the turn and the next state.

Ready to try it?

Open PictorX in your browser — no install, no credit card required to start.

Try Langton's Ant