Cellular Automata
Cellular automata are simulations on a discrete grid of cells which have a finite set of states. At each new timestep, each cell's new state is determined by the states of its neighbours.
For example, the most popular cellular automaton is Conway's game of life, which has the following rules:
Source: wikipedia
- Any live cell with fewer than two live neighbours dies, as if by underpopulation.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by overpopulation.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction
Note that each cell only has 2 states: alive (black) or dead (white).
This simple set of rules gives rise to intricate and complex behaviours over time, with areas of activity that almost seem organic.
The book
Cellular Automata Machines
explores the topic in great depth and presents many other cellular
automata rulesets. Here's one that they call
BRIAN'S BRAIN
, which uses 3 states.
- State 0: if exactly 2 neighbours are in State 1, go to State 1 else do nothing.
- State 1: go to State 2
- State 2: go to State 0
Technical Notes
The cellular automaton simulator program was written in C. It
output .ppm files
which were turned into videos using
ffmpeg.
I chose to output .ppm files since this program was so small
that I didn't want to involve any dependencies beyond the C
standard library. Unlike more common image formats like .bmp
and .png, .ppm is a plaintext format, meaning I could easily
write data to a normal text file without having to worry about
a binary data format. Then ffmpeg just takes care
of the rest.