Generic cellular automaton plugin for bevy.
Bevy Cellular Automaton
bevylife is a generic plugin for cellular automaton. From the classic 2D Conwayβs game of life to WireWorld and 3D rules, the plugin is completely generic and dynamic.
See:
this lib's implementation)How to use
Add a CellularAutomatonPlugin to your bevy app:
A CellularAutomatonPlugin<C, S> has two generic types:
C-> Any type implementingCell, defining the coordinate systemS-> Any type implementingCellState, defining the simulation rules.
CellularAutomatonPlugin as wished, the lib
provides some implementations like:
GameOfLife2dPluginGameOfLife3dPluginImmigrationGame2dPluginImmigrationGame3dPluginRainbowGame2dPluginRainbowGame3dPluginWireWorld2dPluginWireWorld3dPluginCyclicColors2dPluginCyclicColors3dPlugin
impl Cell and impl CellState
components to the entities. The lib provides some implementations like
MooreCell2d or MooreCell3d for cells and ConwayCellState,
WireWorldCellState, etc for states.
You may implement your own cells (coordinate system) and states (rules) as you want, the cellular automaton system is completely dynamic and generic.
For more information you may look at some examples:
- The Classic examples showcase the provided implementations
- the Rock Paper Scissor defines
- the wireworld repository
Pausing
Inserting a SimulationPause resource will pause the simulation, removing it wil resume the it.
Parallel execution and batching
Inserting a SimulationBatch resource will allow parallel computation of cells with custom batch sizes.
Cargo Features
No feature is required for the plugin to work and the main traits Cell and CellState are always available. But you may enable the following features
2D(enabled by default): Enables 2D types like:
MooreCell2d (square cell with 8 neighbors)
* NeumannCell2d (square cell with 4 neighbors)
* HexagonCell2d (hexagon cell with 6 neighbors)
* plugin presets: GameOfLife2dPlugin, ImmigrationGame2dPlugin,
RainbowGame2dPlugin, WireWorld2dPlugin, CyclicAutomaton2dPlugin
3D: Enables 3D types like:
MooreCell3d (cube cell with 26 neighbors)
* NeumannCell3d (cube cell with 6 neighbors)
* plugin presets: GameOfLife3dPlugin, ImmigrationGame3dPlugin,
RainbowGame3dPlugin, WireWorld3dPlugin, CyclicAutomaton3dPlugin
auto-coloring(Example or debug purpose):
CellState trait now requires a color method
bevy_reflect(enabled by default): Enable support for reflection for
Disclaimer
This is probably not the fastest rust implementation of a cellular automaton in rust. For example, using Gosper's HashLife a classic game of life could be much faster.
This library aim is to be generic and dynamic, so that you can integrate cellular automata to any project in bevy, with any rules, in 2D or 3D.
Example projects
[Wire World][wireworld]
The [wireworld-rs][wireworld] project uses bevy_life and wireworld rules to simulate electrical systems.


Internal Examples
For every example pressing space reloads the board.
Note: adding the release flag increases performance for examples
2D Game of life
Run cargo run --example 2dgameof_life --features auto-coloring

2D Immigration game
Run cargo run --example 2dimmigrationgame --features auto-coloring

2D Rainbow game
Run cargo run --example 2drainbowgame --features auto-coloring

2D Cyclic colors
Run cargo run --example 2dcycliccolors --features auto-coloring

2D Rock paper scissor
This example showcases how to define custom rules
Run cargo run --example 2drockpaper_scissor

3D Game of life (4555 rule)
Run cargo run --example 3dgameof_life --features "3D auto-coloring" --no-default-features

[wireworld]: https://github.com/ManevilleF/wireworld-rs "Wire world project"