Crates.io | lifers |
lib.rs | lifers |
version | 0.3.0 |
source | src |
created_at | 2024-05-05 10:03:14.2891 |
updated_at | 2024-07-10 10:42:17.563051 |
description | An advanced cellular automata creation framework |
homepage | |
repository | https://github.com/Froloket64/lifers.git |
max_upload_size | |
id | 1230123 |
size | 27,020 |
A Rust crate that aims to generalize cellular automata creation. Current features include:
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();
}