5 releases
0.1.4 | Oct 5, 2022 |
---|---|
0.1.3 | Oct 5, 2022 |
0.1.2 | Oct 4, 2022 |
0.1.1 | Oct 4, 2022 |
0.1.0 | Oct 2, 2022 |
#1358 in Math
28 downloads per month
26KB
612 lines
luacells
A Rust text-based cellular automata simulator that uses Lua for rule definitions.
Installation
With cargo:
cargo install luacells
Usage
luacells rules/life.lua
luacells --help # For more information
You can find the controls at the bottom of the viewer.
Rule format
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 previous state of that cell
- The previous states in the square neighborhood around the cell
The neighborhood is given as a table in this order:
- North
- South
- East
- West
- Northeast
- Southeast
- Northwest
- Southwest
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.
Pattern format
The patterns are just lists of rows of numbers.
The rows are delemited by semicolons, and the cells are delemited by commas.
This repository
This repository contains the Rust source code along with some rules and patterns, in the rules
and patterns
directories.
Dependencies
~4–12MB
~152K SLoC