After looking at Conway's game of life I have been looking at other forms of cellular automata. This lead me to discover Langton's ant, which is a different kind of cellular automata where an agent (namely an ant) is used to turn the squares on or off as it travels around a grid.
The rules of Langton's ant are quite simple. The ant simply follows two rules as it moves around the grid.
- At a white square, turn 90° clockwise, flip the colour of the square, move forward one unit.
- At a black square, turn 90° counter-clockwise, flip the colour of the square, move forward one unit.
This can be represented in code by looking at the current state of the square that the ant is stood on and then performing an action. Movement in a particular direction is achieved by adding or subtracting from the x or y coordinates depending on which way the ant is pointing.