#cellular-automata #definition #lua #rule #text-based #pattern #simulator

app luacells

A Rust text-based cellular automata simulator that uses Lua for rule definitions

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

#716 in Math

25 downloads per month

MIT license

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:

  1. The previous state of that cell
  2. The previous states in the square neighborhood around the cell

The neighborhood is given as a table in this order:

  1. North
  2. South
  3. East
  4. West
  5. Northeast
  6. Southeast
  7. Northwest
  8. 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–14MB
~153K SLoC