https://github.com/hugcis/rust_ca
A Rust cellular automata simulator that can output GIF animations.
https://github.com/hugcis/rust_ca
cellular-automata cellular-automaton rust rust-lang
Last synced: about 1 year ago
JSON representation
A Rust cellular automata simulator that can output GIF animations.
- Host: GitHub
- URL: https://github.com/hugcis/rust_ca
- Owner: hugcis
- License: mit
- Created: 2021-01-20T20:18:52.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-05T15:05:39.000Z (over 3 years ago)
- Last Synced: 2025-03-25T06:51:12.434Z (about 1 year ago)
- Topics: cellular-automata, cellular-automaton, rust, rust-lang
- Language: Rust
- Homepage:
- Size: 1.26 MB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rust Cellular Automata
[](https://crates.io/crates/rust_ca)
[](https://github.com/hugcis/rust_ca/actions/workflows/rust.yml)
This is a command-line tool and a library to simulate and search the space of simple cellular
automata (with smallish neighborhoods).
The tool outputs CA simulations in the form of GIF files.
## Install the tool
Run the following command to install on your system:
```
cargo install rust_ca
```
To use the library in another Rust project add the following to your `Cargo.toml` dependencies:
```toml
[dependencies]
rust_ca = "0.2.1"
```
## Example
The following command will run a CA with a rule numbered `16855021099980290151`
(you can find it in this repository).
The initial configuration is specified in `exploding.pat` (the initial
configuration is random by default). The CA has 3 states and is 128x128 cells.
We want the output GIF file to represent 2400 time steps, but displaying only 1
in 10.
```
rust_ca -n 3 -f rules/3_states/16855021099980290151.map.comp \
-p patterns/exploding.pat -k 10 -s 128 --delay 0 -t 2400
```
This results in the following `test.gif` file:

### Generate random CA GIFs
This generates 200 distinct CA ran for 2400 steps (only showing one in 10) with
4 states.
**Warning:** This command creates 200 GIFs for a total size of ~500MB.
``` sh
cargo build --release
mkdir rgen
for i in $(seq 0 200); do
rust_ca -n 4 -k 10 -s 128 --delay 0 -t 2400 --rotate 1 --symmetric \
> rgen/test_$i.gif
done;
```
## CLI usage
The CLI usage is:
```
Rust CA 0.2.2
Hugo Cisneros
A CLI CA simulator. With no options, this runs a randomly sampled CA rule with 2 states for 50 steps
and outputs it as a gif file `test.gif`
USAGE:
rust_ca [OPTIONS]
OPTIONS:
--delay
[default: 10]
-f, --file
File to read a rule from or write to. The file must contain a valid rule for the
corresponding number of states
-h, --help
Print help information
--horizon
[default: 1]
-k, --skip
Steps to skip at every time step for the output [default: 1]
-n, --states
Number of states of the CA [default: 2]
-o, --output
A file to write the GIF to. Defaults to standard output
-p, --pattern
-r, --rule
Specify one of the implemented CA rule [possible values: GOL]
--rotate
[default: 0]
--rule-sampling
[default: dirichlet] [possible values: uniform, dirichlet]
-s, --size
The size of the 2D CA grid [default: 128]
--symmetric
Make the rule symmetric (this will also apply to rules passed as files)
-t, --steps
Simulation time [default: 50]
--use-tiled
Use a tiled CA (defaults to true when the size is a multiple of TILE_SIZE)
-V, --version
Print version information
-w, --write-rule
File to read a rule from or write to. The file must contain a valid rule for the
corresponding number of states
```