Cellular Automata (WIP)
This Cellular Automata application is a C++ project with the aim of being able to simulate different types of Cellular Automata, including life-like (2D and 3D), continuous (smooth-life), and various animation-like simulations (e.g. fire simulations, water simulations, etc.). Currently I only have 2D-life-like implemented.
I have always enjoyed making Cellular Automata simulations, ever since I first learned about Conway's Game of Life. At some point, I began to treat Game of Life as hello world code for any new programming language I've learned, though now I've expanded this to making general life-like Cellular Automata.
In the past, I have programmed Conway's Game of Life, or general life-like Cellular Automata, in at least the following languages:
- C
- C++
- Unity
- hlsl (via Unity)
- glsl
- Python
- Java
- JavaScript
- Arduino
- Netlogo
- Scratch
See below for a simple JavaScript version of this simulation.
What are Cellular Automata?
A Cellular Automaton is a simulation predicated on simple rules. The common example of this is Conway's Game of Life, in which you begin with a grid of cells, with each cell either being alive or dead. Every iteration, each cell in the grid will look at the eight neighbouring cells (the moore neighbourhood) and if a dead cell is surrounded by exactly three live cells, it will become alive (due to reproduction). If a live cell is surrounded by fewer than two or more than three live cells it will die (due to underpopulation or overpopulation respectively).
See the wiki here for more details on Cellular Automata and here for more on Conway's Game of Life.
Conway's Game of Life
Notation
The notation I use to define the rules for a 2D life-like Cellular Automaton is the BSG notation, in which each of the components B-S-G are followed by numbers. The numbers following B indicate the number of neighbours a dead cell must have to become alive. The numbers following S indicate the number of neighbours a live cell must have to stay alive. And the number following G indicate the number of generations (how many iterations it takes for a dead cell to be viable for life again).
With this notation, Conway's Game of Life would be notated as B3S23 (with G being ommitted for values of 1). B3 indicating exactly three neighbours are required to be born, and S23 indicating two or three neighbours are required to survive.
Libraries
Dear ImGui | GUI library for creating UI widgets on top of a window. Generally used for debug windows, but can be used for application layout (as I often do). |
glad | Library for interfacing with the GPU through OpenGL. |
glm | Utility library with useful data structures and functions for graphics and 3D maths, matching those seen in glsl (e.g. vec3, mat4, normalize). |
SDL2 | GUI library for C++, used to create the main application window and handle user input events. Often used for games and simulations. |
stb | Utility library for reading and writing textures/images. |
Examples
Conway's Game of Life (B3S23) | Day and Night (B3678S34678) |
---|---|
Replicator (B1357S1357) | B1S1357G100 |
Web App
Death Rules:
Generations: