2 releases
new 0.1.1 | Mar 27, 2025 |
---|---|
0.1.0 | Mar 23, 2025 |
#373 in Machine learning
206 downloads per month
245KB
2K
SLoC
LiveIron
Description
A Performant cellular automata simulator library with visualisation capabilities built in Rust. The library is designed to be flexible and easy to use, with a focus on performance. It provides a simple API for creating and running cellular automata simulations, as well as visualising them using the dioxus
library.
Future plans include adding support for evolving cellular automata using genetic algorithms, as conceptualised by Mitchell et al.
Components
-
state
: One of the two atomic elements of a cellular automaton, the state module contains thestate
struct, which is used to represent the state of a cell in the simulation. It also containsstate
implementations for Conway's Game of Life and Langton's Ant. -
rule
: One of the two atomic elements of a cellular automaton, the rule module contains therule
trait that defines how the state of a cell changes. It also containsrule
implementations for Conway's Game of Life and Langton's Ant. -
board
: The board module contains theboard
struct, which is the main data structure used to represent the board of cells in the simulation. It contains methods and structs to create the board with a specifiedBoundaryCondition
, read and write cell states, and convert the board to its representation for visualisation. -
neighbourhood
: The neighbourhood module contains theneighbourhood
struct andneighbourhood
implementations for theMoore
andVonNeumann
neighbourhoods. Theneighbourhood
struct is used to define the neighbourhood of a cell in the simulation, and implements methods to efficiently calculate the neighbours of a cell and return their states and coordinates. -
automaton
: The most important module, the automaton module contains theautomaton
struct, which is used to represent the cellular automaton simulation. It contains methods to create an automaton with a specified board and a set of rules, evolve the automaton by applying the rules to the board, and visualise the automaton using theui
module. -
ui
: Theui
module uses thedioxus
library to create a window and render the automaton to the screen. The module contains main simulation function as well as several Dioxus components used to visualise the automaton.
Usage
To use the library, add the following to your Cargo.toml
:
[dependencies]
live-iron = "0.1.0"
Using the library is both simple and flexible. Here's an example of Conway's Game of Life:
// Create a 20x20 board with a glider pattern
let mut initial_state: Vec<Vec<GameOfLifeState>> = vec![vec![GameOfLifeState::Dead; 20]; 20];
initial_state[0][0] = GameOfLifeState::Alive;
initial_state[0][2] = GameOfLifeState::Alive;
initial_state[1][1] = GameOfLifeState::Alive;
initial_state[1][2] = GameOfLifeState::Alive;
initial_state[2][1] = GameOfLifeState::Alive;
// Create a board with the initial state and periodic boundary conditions
let mut board: Board<GameOfLifeState> = Board::new(initial_state, BoundaryCondition::Periodic);
// Create a Game of Life rule and an automaton with the board and rule
let rule: GameOfLifeRule = GameOfLifeRule;
let mut automaton: automaton::Automaton<'_, GameOfLifeState> = automaton::Automaton::new(&mut board, vec![Box::new(rule)]);
// Visualise the automaton for 100 steps with an interval of 500ms.
let _ = automaton.visualise(100, 500);
Dependencies
~6–50MB
~735K SLoC