Constructor
new LifelikeAutomaton(ruleString, rowsopt, colsopt)
Construct a lifelike cellular automaton.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ruleString |
string | A string describing the rule for the automaton, in born/survive format (e.g. "B3/S23" or just "3/23" for Conway's Game of Life). | ||
rows |
number |
<optional> |
20 | The number of rows to use. |
cols |
number |
<optional> |
20 | The number of columns to use. |
- Source:
Extends
Members
data
The main data array.
Note that the convention used here
(and elsewhere in this package) is that data[row][col] corresponds
to the row-th cell down and the col-th cell to the right, indexed
from zero (as one would normally expect).
- Inherited From:
- Source:
Methods
addPostUpdate(postUpdate)
Add a function to be executed after a cell is updated.
This can be used to speed up tasks such as image rendering,
since it saves you having to iterate over the array more
than once for each frame.
Parameters:
Name | Type | Description |
---|---|---|
postUpdate |
function | The function to run after each cell is updated. Should take three params: cellValue, rowIndex, and colIndex. |
- Inherited From:
- Source:
prettyPrint(mapopt) → {string}
Get a nice string representation of the state of the automaton.
Same as module:cellerity.Automaton#prettyPrint, but with
a default map function that works well for lifelike automata.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
map |
function |
<optional> |
A function to apply to each cell value, returning the string to be used to represent the cell. |
- Overrides:
- Source:
Returns:
A string representation of the automaton's state.
- Type
- string
reset()
Set the automaton's data to initial conditions
- Inherited From:
- Source:
setDimensions(rows, cols)
Change the automaton's dimensions.
This will reset the automaton's state to conform to the chosen
dimensions, using the automaton's current initializer function.
Parameters:
Name | Type | Description |
---|---|---|
rows |
number | The new number of rows. |
cols |
number | The new number of columns. |
- Inherited From:
- Source:
setEdgeMode(edgeMode)
Set the automaton's edge behaviour.
If "toroid", the neighbourhood of cells near the edge of the
grid will "wrap around" horizontally and vertically.
If "cylinder", the neighbourhood will wrap horizontally only,
and cells in the top and bottom row will never change.
If "freeze", cells on the edge of the grid will never change.
Parameters:
Name | Type | Description |
---|---|---|
edgeMode |
string | The edge mode, one of "toroid", "cylinder", "freeze". |
- Inherited From:
- Source:
setInitializer(initial)
Change the function used to initialize the automaton's state,
and then reset the automaton to the new initial conditions.
If a 2D array is provided, the automaton will be initialized
so as to match the given array as closely as possible, causing
the provided array to repeat in a tiled fashion if it is not
large enough to fully cover the automaton's data grid.
Parameters:
Name | Type | Description |
---|---|---|
initial |
initializerFunction | Array.<Array> | Either an initializer function, or a 2D array of cell values, to use to initialize the automaton's state when resetting. |
- Inherited From:
- Source:
setPostStep(postStep)
Set a function to be executed after each "step".
This could be useful for integrating with other functionality
(e.g. image rendering or mouse interactivity), or adding
internal functionality (e.g. tracking # of living cells, entropy, etc.)
Parameters:
Name | Type | Description |
---|---|---|
postStep |
function | A function to be executed after each generation. |
- Inherited From:
- Source:
setRuleset(ruleset)
Change the automaton's ruleset.
Parameters:
Name | Type | Description |
---|---|---|
ruleset |
string | Array.<string> | The rule or rules to use for the automaton, in "B/S" format (e.g. "B3/S23" or just "3/23" for Conway's Game of Life). If a list is provided, the rules will be composed in order. |
- Overrides:
- Source:
Throws:
-
An error message if the rule is not valid.
- Type
- string
step(nopt)
Perform one or more iterations of evolution according to
the automaton's rule.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
n |
number |
<optional> |
1 | The number of iterations to perform |
- Inherited From:
- Source: