Crates.io | luacells |
lib.rs | luacells |
version | 0.1.4 |
source | src |
created_at | 2022-10-02 22:09:16.006617 |
updated_at | 2022-10-05 20:46:21.873774 |
description | A Rust text-based cellular automata simulator that uses Lua for rule definitions. |
homepage | https://github.com/nph278/luacells |
repository | https://github.com/nph278/luacells |
max_upload_size | |
id | 678608 |
size | 37,751 |
A Rust text-based cellular automata simulator that uses Lua for rule definitions.
With cargo:
cargo install luacells
luacells rules/life.lua
luacells --help # For more information
You can find the controls at the bottom of the viewer.
Rules are given as lua programs with three globals: Update
, Display
, and States
.
Example (Conway's Game of Life):
Update = function(c, n)
local sum = 0
for _, v in ipairs(n) do
sum = sum + v
end
if c == 0 then
if sum == 3 then
return 1
else
return 0
end
else
if sum == 2 or sum == 3 then
return 1
else
return 0
end
end
end
Display = function(n)
if n == 0 then return " " end
if n == 1 then return "()" end
end
States = 2
States
States
is simply the number of states a cell can be in.
Update
Update
is a function describing how to update a cell.
It is given two arguments:
The neighborhood is given as a table in this order:
Display
Display
is the function that displays a cell.
It is given the value of the cell and should return a string of length 1 or 2.
Randomize
You can optionally add Randomize = true
to the rule file to randomize on startup.
The patterns are just lists of rows of numbers.
The rows are delemited by semicolons, and the cells are delemited by commas.
This repository contains the Rust source code along with some rules and patterns, in the rules
and patterns
directories.