Maths Index The Ant World

## Langton's Ant - Background

Langton's ant walks on a grid of square cells, changing the colour of each cell that she visits, and turning to the left or right depending on a rule.

The rule consists of a list of commands given by the characters "R" and "L", meaning turn right or turn left. So, for example, we might have the rule RRRLLR. Each letter in the rule is associated with a colour.

When the ant lands on a cell, she looks up the command associated with the colour of the cell, and turns to the right or left as dictated by the rule. Then she changes the colour of the cell to the next colour in sequence, and moves forward one square.

A fuller description and many examples can be found in Wikipedia.

In this implementation, I have provided a sequence of twelve colours plus white. This means that we can have rules of up to thirteen commands. For shorter rules fewer colours are used. So, for example, the rule RLR will only use three colours, white, red and blue. In this rule of just three commands, when the ant lands on a white cell that cell changes to red, a red cell changes to blue, and a blue cell changes back to white.

To begin, the whole grid is white, the ant is in the middle facing downwards. So, the first step she takes will produce a blob of red in the middle of the field.

## The Controls

There are three modes for running the animation.

• The Single Step will let the ant take just one step.
• The Run button will start the animation at the chosen speed and Stop will stop it again.
• The Go button will run the animation at top speed for the given number of steps.

If the ant moves off the visible grid, you can move the grid up, down, left or right. The ant lives in a world much larger than the visible grid.

## Customising the Animation

You can enter a rule of up to 13 commands consisting of the characters "R" and "L" (not case sensitive).

You can set the zoom factor and the speed of the animation (1 to 10).

Then you should press the Accept changes button, to set your choices.

In addition to the standard commands, I have included "S" meaning go straight on, and "U" meaning do a U-turn.

## Examples

Sometimes the ant draws a pathway or track. It will then continue to add to path for ever. Here are some rules that produce a pathway immediately.

 RRL at 500 steps. RRRL at 600 steps RRRLLLRRRLLL at 1000 steps

Sometimes the ant messes around for a while before embarking on a pathway.

 RLRL at step 11200. LLRRRLRLRLLR at step 40000

And here we have some more remarkable patterns.

A growing triangle with rule RRLLLRLLLRRR

 20K steps 40K steps 60K steps 80K steps

A square that grows. Rule RRLRR

You might also like to try the rules LRRRRRLLR, LRRRRLLLRRR and RLLLLRRRLLLR. According to Aresh Pourkavoos these make squares containing spiralling paths. In the first one the paths are chaotic, in the second the paths make an Archimedes' spiral, and in the third a logarithmic spiral.