Home :: ALife :: Langton's Ants

Langont's Ant follows a few simple rules:

  1. The Ant toggles the color of the square where he is currently
  2. The Ant advances in the direction he is facing
  3. If the new square is off, then the Ant turns to the right by 90 degrees
  4. If the new square is on, then the Ant turns to the left by 90 degress

After roughly 10000 iterations, the ant will start to build a repeating pattern called a bridge.

The grid size, the pixel size, and the pixel padding are easily changed at the beginning of the JavaScript in the SVG file. Feel free to download it and to experiment with different settings.


Version 2.0 of Langton's Ants uses a radically different approach to the Bitmap implementation. In version 1.0, I created a separate <rect> element for each and every grid cell ( 75x75 = 5625 <rect> nodes). Needless to say, the startup time, which included the creation of all of those <rect> elements, was slow and I'm sure memory intensive. By changing my approach, startup time and memory are no long concerns.

Now, each row of the grid is a single <line> element. Pixels are turned on and off by manipulating that <line>'s dash-array. As a result, I'm able to increase the grid size without much of a penalty. I've been amazed that even with pixels sizes of 1 and pixel padding of 0 (like a true bitmap image), I'm still getting reasonable startup times and processing speeds.

Read more about the Bitmap implementation here.


For those of you who are interested in the display in the upper left-hand corner...

  1. G = generation number
  2. S = seconds of execution
  3. A = average generations per second.