#cellular-automata #framework #game-of-life

lifers

An advanced cellular automata creation framework

1 unstable release

new 0.1.0 May 5, 2024

#64 in Simulation

Download history 136/week @ 2024-05-03

136 downloads per month
Used in lifers-ascii

MIT license

11KB
179 lines

lifers

A Rust crate that aims to generalize cellular automata creation. Current features include:

  • Easy creation using the builder pattern
  • Fast simulation engine
  • Interface to create custom frontends

Usage

An example illustrating Conway's Game of Life implementation in lifers:

use lifers::prelude::*;

fn main() {
    // Use a 100x100 grid
    let mut game = Automaton::build(100, 100)
        // Initialize all cells with random states (alive or dead)
        .init(|_| random::<bool>())
        // Count neighbors in radius of 1 for each cell
        .map(|(x, y), _, cells| lifers::count_neighbors(cells, (x, y), 1, |b| *b))
        // Change cells' state depending on the number of neighbors
        .run(|(_, _), is_alive, neighbors_n| match is_alive {
            true => (2..=3).contains(neighbors_n),
            false => *neighbors_n == 3,
        });
    
    // Compute the next generation
    game.step();
}

No runtime deps