Ant-ology

Following up on cellular automata after my previous Game of Life project, I sort of rediscovered Langton’s Ant. It’s another example of extremely simple rules, leading to some intriguing arm wrestling between order, complexity and chaos.

Langton’s ant lives on an infinite grid of squares. Every next move it makes is determined by these simple rules:

  • If it’s on a black square, it turns left and moves to the next square in that direction
  • If it’s on a white square, it turns right and moves to the next square in that direction
  • The square it moves from reverses color

The grid size needed for properly simulating the process made me use a Wemos D1 R2 board instead of my faithful Arduino Uno. This first sketch is as simple as the ant’s rules. It maps a 106×160 cell grid on a 320×480 pixel display (3×3 pixel cells).

Infinity of the grid is simulated by ‘folding’ it in both dimensions (toroid shape), so the famous ‘highway’ will lead the ant back to its self created chaos, from where it will try to build new highways.

Meanwhile, I’ve developed some┬ámulti-ant ideas, so more sketches may follow.

 

(For this video, I started with an all black grid and removed the delay at the end of the loop() function in order to turbo-boost the ant)