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
is simply the number of states a cell can be in.
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
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.
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.