This project implements a 3D Cellular Automaton (CA) using the Bevy engine. Cellular automata are systems where cells evolve over discrete time steps based on the states of neighboring cells. By extending CA into three dimensions, this project offers dynamic and visually engaging simulations.
cellular-automata.mp4
This project was inspired by and based on the article "3D Cellular Automata" by Jason Rampe. You can read the original article here.
In cellular automata, neighborhoods define which cells around a given cell influence its behavior—such as its birth, survival, or death. In a 3D CA, two common types of neighborhoods are used:
The Moore neighborhood in 3D consists of the 26 cells surrounding the current cell, similar to the cells in a Rubik’s cube with the center being the current cell. Imagine a 3x3x3 grid of small cubes; the center cube is the current cell, while the other 26 cubes are its neighbors.
The Von Neumann neighborhood in 3D includes only the 6 cells that share a face with the current cell. These are the cells located along the positive and negative X, Y, and Z axes, forming a 3D cross or "plus sign."
Rules dictate how cells transition between states based on their neighborhood configuration. This project supports customizable rule configurations applied to the simulation. Here are two examples:
- Survival: A cell in state 1 survives if it has 4 neighboring cells.
- Birth: A new cell is born in an empty location if it has 4 neighbors.
- States: The automaton has 5 states. Newly born cells start in state 4, fade to state 1, and eventually die in state 0.
- Neighbours: Uses the Moore neighborhood.
- Survival: Alive cells with 2, 6, or 9 neighbors survive.
- Birth: New cells are born in empty locations if they have 4, 6, 8, 9, or 10 neighbors.
- States: Supports 10 states, with 8 intermediate states.
- Neighbours: Uses the Moore neighborhood.
In multi-state cellular automata, cells transition through several states before dying. For example, in a 5-state automaton, a new cell starts in state 4 and progresses through states 3, 2, and 1 before reaching state 0 (dead). This fading effect adds complexity and visual interest to the simulation.
To enhance the visual representation of the 3D Cellular Automaton, three color methods have been implemented:
Cells are colored based on their distance from the center of the 3D space, creating a gradient effect that distinguishes cells by their location.
This method uses Linear Interpolation to color cells based on their current state, providing smooth transitions between states and visualizing state changes.
Cells are colored based on the number of neighboring cells in a specific state. This method produces a gradient effect that reflects the density or influence of neighboring cells.
To run the project locally, follow these steps:
- Clone the repository:
git clone https://github.com/gbPagano/cellular-automata.git
cd cellular-automata
- Build and run the project:
cargo run --release
Feel free to submit a PR if you have suggestions, bug fixes, or new features.