Crate bevy_life

source ·
Expand description

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:

§Bevy versions

The main branch follows the released version of bevy but I provide the bevy-main branch to follow the main branch of bevy

bevy_lifebevy
0.3.x0.6.x
0.4.x0.7.x
0.5.x0.8.x
0.6.x0.9.x
0.7.x0.10.x
0.8.x0.11.x
0.9.x0.13.x

§How to use

Add a CellularAutomatonPlugin to your bevy app:

A CellularAutomatonPlugin<C, S> has two generic types:

  • C -> Any type implementing Cell, defining the coordinate system
  • S -> 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:

§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):
    • Enables CellStateMaterials resource to contain material handles
    • The CellState type now requires to build a CellStateMaterials
    • All CellState components with materials will be colored according to their type.

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

Structs§

  • Global Cell container resource , uses a Hashmapto allow non-continuous cells.
  • Generic Cellular Automaton plugin. It will register systems for the matching Cell and CellState types.
  • Classic cellular automation state and rules following Conway’s game of life 4555 rules:
  • Classic cellular automation state and rules following Conway’s game of life classic 2333 rules:
  • Basic cyclic cellular automaton state and rules. The rules are the following:
  • Hexagonal 2D cell. It has 6 neighbors and uses IVec3 coordinates (Cubic coordinates).
  • Moore 2D cell. It has 8 neighbors and uses IVec2 coordinates.
  • Neumann 2D cell. It has 4 neighbors and uses IVec2 coordinates.
  • Resource to insert for parallel queries and batching
  • Resource to insert to pause the cellular automaton simulation

Enums§

  • Classic cellular automation state and rules following Conway’s game of life variation: The immigration game.
  • Classic cellular automation state and rules following Conway’s game of life variation: The immigration game.
  • Wireworld is a cellular automaton that simulates electronic devices and logic gates by having cells represent electrons traveling across conductors. Wireworld uses three possible cell states and has the following rules:

Traits§

  • Trait defining a Cell, every cell type (2d, 3d, hexagonal, etc) must implement this trait and define an associated Coordinates type
  • This trait defines the state of any given Cell. The trait implementation will define the cellular automaton rules which will be automatically applied.

Type Aliases§

  • Cellular automaton plugin type for Colored Cyclic cellular automaton in 2D
  • Cellular automaton plugin type for Conway’s Game of life in 2D.
  • Cellular automaton plugin type for a binary (blue and orange) Immigration Game of life variation in 2D.
  • A CellMap implementation for Cell2d
  • Cellular automaton plugin type for a binary (blue and orange) Immigration Game of life variation in 2D.
  • Cellular automaton plugin type for WireWorld in 2D