Crates.io | bevy_life |
lib.rs | bevy_life |
version | 0.10.1 |
source | src |
created_at | 2021-09-30 09:27:40.249326 |
updated_at | 2024-07-15 09:07:45.460627 |
description | Generic and dynamic cellular automaton lib for bevy |
homepage | |
repository | https://github.com/ManevilleF/bevy_life |
max_upload_size | |
id | 458642 |
size | 153,808 |
bevy_life
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:
Wireworld
implementation (see
this lib's implementation)The main
branch follows the released version of bevy
but I provide the bevy-main
branch
to follow the main
branch of bevy
bevy_life |
bevy |
---|---|
0.3.x | 0.6.x |
0.4.x | 0.7.x |
0.5.x | 0.8.x |
0.6.x | 0.9.x |
0.7.x | 0.10.x |
0.8.x | 0.11.x |
0.9.x | 0.13.x |
0.10.x | 0.14.x |
Add a CellularAutomatonPlugin
to your bevy app:
A CellularAutomatonPlugin<C, S>
has two generic types:
C
-> Any type implementing Cell
, defining the coordinate systemS
-> Any type implementing CellState
, defining the simulation rules.You may add as many generic CellularAutomatonPlugin
as wished, the lib
provides some implementations like:
GameOfLife2dPlugin
GameOfLife3dPlugin
ImmigrationGame2dPlugin
ImmigrationGame3dPlugin
RainbowGame2dPlugin
RainbowGame3dPlugin
WireWorld2dPlugin
WireWorld3dPlugin
CyclicColors2dPlugin
CyclicColors3dPlugin
Then you may use bevy as usual and add 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:
Inserting a SimulationPause
resource will pause the simulation, removing
it wil resume the it.
Inserting a SimulationBatch
resource will allow parallel computation of
cells with custom batch sizes.
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)GameOfLife2dPlugin
, ImmigrationGame2dPlugin
,
RainbowGame2dPlugin
, WireWorld2dPlugin
, CyclicAutomaton2dPlugin
3D
: Enables 3D types like:
MooreCell3d
(cube cell with 26 neighbors)NeumannCell3d
(cube cell with 6 neighbors)GameOfLife3dPlugin
, ImmigrationGame3dPlugin
,
RainbowGame3dPlugin
, WireWorld3dPlugin
, CyclicAutomaton3dPlugin
auto-coloring
(Example or debug purpose):
CellState
trait now requires a color
methodbevy_reflect
(enabled by default): Enable support for reflection for
common typesThis 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.
The wireworld-rs project uses bevy_life
and wireworld rules to simulate electrical systems.
For every example pressing space reloads the board.
Note: adding the release flag increases performance for examples
Run cargo run --example 2d_game_of_life --features auto-coloring
Run cargo run --example 2d_immigration_game --features auto-coloring
Run cargo run --example 2d_rainbow_game --features auto-coloring
Run cargo run --example 2d_cyclic_colors --features auto-coloring
This example showcases how to define custom rules
Run cargo run --example 2d_rock_paper_scissor
Run cargo run --example 3d_game_of_life --features "3D auto-coloring" --no-default-features