Cellular Automata in ROOT

It’s possible to set up an interactive, updating canvas in ROOT via use of TApplication, here some patterns generated by an implementation of Langton’s Ant are shown. Possibly my favourite cellular automaton, Langton’s ant follows the simplest of rules:

  • On white: turn to coloured, rotate \(\pi/2\) clockwise, move forward.
  • On coloured: turn to white, rotate \(\pi/2\) counter-clockwise, move forward.

After an apparent chaotic period, the automaton starts producing a long ‘road’ pattern. Here four ants interact with each other on a wrapping grid, leaving different coloured tiles but operating under the same rules (tiles are coloured, or white).

Ant

Extensions to the Ant’s rules are typically called termites. By adding an additional state to the ant, a spiral may be produced.

Ant

Or a golden rectangle, here using the rule set:

  • On white and state 0: set to state 1, turn to coloured, rotate \(\pi/2\) counter-clockwise, move forward.
  • On white and state 1: turn to coloured, rotate \(\pi/2\) clockwise, move forward.
  • On coloured and state 0: set to state 1, rotate \(\pi/2\) counter-clockwise, move forward.
  • On coloured and state 1: set state to 0, turn to white, move forward.

Ant

Other variants include adding more coloured states and altering the direction of travel based on the colour of the square.

Ant