Constructor
new Automaton(ruleset, rowsopt, colsopt)
Create an automaton instance.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ruleset |
ruleset | The rule that guides the automaton's evolution | ||
rows |
number |
<optional> |
20 | The number of rows of cells to use. |
cols |
number |
<optional> |
20 | The number of columns of cells to use. |
- Source:
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).
- 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. |
- Source:
prettyPrint(mapopt) → {string}
Get a human-friendly string representation of the current
state of the automaton. 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).
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. |
- Source:
Returns:
The string representation of the current state of
the automaton.
- Type
- string
reset()
Set the automaton's data to initial conditions
- 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. |
- 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". |
- 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. |
- 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. |
- Source:
setRuleset(ruleset)
Change the automaton's ruleset.
Parameters:
Name | Type | Description |
---|---|---|
ruleset |
ruleset | The new update function(s) for the automaton. |
- Source:
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 |
- Source: