Langton’s Ant

Just finished my rough cut of an implementation of Langton’s Ant. It is a so called turning machine, invented by Chris Langton in 1986.

The application consist of a grid containing all white squares, and the “ant” which is just a reference to the current position on the board (marked with a red square). For every step of the iteration, the ant follows these two simple rules:

  • If the ant is on a white square, turn 90° left, paint the square black and move forward one tile
  • If the ant is on a black square, turn 90° right, paint the square white and move forward one tile

This, in spite of the very simple rule-set, results in some quite complex patterns, and at a certain point the ant starts building a “highway”, which is about 100 continuously repeated steps, forming a track in the southwestern direction.

Here are some snapshots of the grid after a certain number of iterations

100 iterations
Langton’s Ant - 100 steps

1000 iterations
Langton’s Ant - 1000 steps

10000 iterations
Langton’s Ant - 10000 steps

Aaand, we have a highway! (about 13000 iterations)
Langton’s Ant - The highway has been built

 See for yourself here (be patient, it might take a moment to load).

Source code can be found here (Flex Builder 2 archive file).

PS. The simulation tends to run faster if you move your cursor outside the SWF area, and to be honest, I have no idea why!?

0 Responses to “Langton’s Ant”



  1. No Comments Yet

Leave a Reply