4 releases (2 breaking)

0.3.0 Jul 10, 2024
0.2.1 Jun 1, 2024
0.2.0 May 26, 2024
0.1.0 May 5, 2024

#59 in Simulation

Download history 109/week @ 2024-04-29 38/week @ 2024-05-06 145/week @ 2024-05-20 215/week @ 2024-05-27 37/week @ 2024-06-03 18/week @ 2024-06-10 4/week @ 2024-06-17 119/week @ 2024-07-08

127 downloads per month
Used in 2 crates

MIT license

24KB
452 lines

lifers

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

  • Easy creation using the builder pattern
  • Fast simulation engine
    • Multiple versions for different use cases
    • SIMD potential
  • Very ergonomic design for creating simulations
    • Full support for the builder pattern
    • Multiple data collection functions for an automaton
  • Arbitrary types support for cells' state and associated data
  • Interface to create custom frontends (WIP)

Usage

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

use lifers::prelude::*;
use rand::random;

fn main() {
    // Use generic automaton with a 100x100 grid
    let mut game = generic::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| generic::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();
}

Dependencies

~620KB
~12K SLoC