Skip to content

gbPagano/cellular-automata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

3D Cellular Automaton

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.

Neighborhoods

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:

Moore Neighborhood

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.

Von Neumann Neighborhood

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."

Rule System

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:

Rule 445 (4/4/5/M)

  • 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.

Builder Rule (2,6,9/4,6,8-10/10/M)

  • 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.

Multi-State Automata

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.

Color Methods

To enhance the visual representation of the 3D Cellular Automaton, three color methods have been implemented:

Distance to Center

Cells are colored based on their distance from the center of the 3D space, creating a gradient effect that distinguishes cells by their location.

State Lerp

This method uses Linear Interpolation to color cells based on their current state, providing smooth transitions between states and visualizing state changes.

Neighbors Lerp

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.

Running the Project

To run the project locally, follow these steps:

  1. Clone the repository:
git clone https://github.com/gbPagano/cellular-automata.git
cd cellular-automata
  1. Build and run the project:
cargo run --release

Feel free to submit a PR if you have suggestions, bug fixes, or new features.