Typically Langton’s Ant is a 2D grid based simulation using very simple rules to demonstrate complex emergent behaviour. It contains a single “ant” that uses the following rules:
- Move 1 grid square up, down, left or right
- If the square is white, the ant rotates its direction 90 degrees to the left
- If the square is black, the ant rotates its direction 90 degrees to the right
- Invert the colour of the swap, i.e. black becomes white, white becomes black
- Repeat for whatever length of time you’d like
Despite these very simple rules the ant will demonstrate quite complicated behaviour. Typically the ant progresses through phases of creating interesting geometric patterns, then moving more randomly and finally a “highway” pattern emerges that repeats indefinitely. YouTube is full of long running simulations if you’re interested in them.
This was a quick afternoon’s worth of a prototype of an idea for ProcJam 2021 where the theme was “Change”. What’s the point of paying for hosting if you don’t post half formed ideas from time to time! I don’t remember why I decided to experiment with Langton’s Ant. Anyhow, I modified the original idea in the following ways:
- There are multiple ants to start with and the User can add more at any time.
- Ants are randomly assigned an initial colour: Red, Green or Blue.
- If the square is black, change it to the ant’s current colour
- If the square has a colour, that isn’t the ant’s current colour then blend it with ant’s current colour
- If the square is the ant’s current colour, change it to black.
I used chroma.js to help with blending colours. The deltaE function returns the difference between colours. I used maximum difference value to determine when to apply rules 4 and 5 because some colour differences were so slight (and imperceptible to my eyes at least) the changes – especially rule 5 – looked broken.