new Automaton($container, rows, cols, stepFn, renderFn, sopt)
A prototype to represent a cellular automaton.
The automaton uses a lower-right quadrant zero-indexed coordinate system. The horizontal axis is labeled the x axis and numbered from left to right in whole number increments. The vertical axis is labeled the y axis, and numbered from top to bottom in whole-number increments. When describing a cell it's x coordinate is specified first, and its y coordinate second. Hence, the cell in the top-left corner has the coordinates (0, 0), the second cell in the top row has the coordiantes (1, 0), and the cell in the second cell on the left-most column has the coordinates (0, 1).
The automaton will be represented within the DOM by an automatically generated table, with the cells that make up the automaton as table cells. The table will be generated within a given container.
The constructor expects to be passed a jQuery object representing a sigle
container element. That element will be emptied, and the table
representing the automaton will then be added to it. The class
bartificer-ca-container
will be added to the conainer, and the
generated table will have the class bartificer-ca-automaton
added.
The table. A reference to the constructed object will be added to both
the container and the table as the data attribute
data-bartificer-object
(bartificerObject
from JavaScipt's point of
view).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
$container |
jQuerySingleContainer
|
A jQuery object representing the container that will be converted into the cellular automaton. |
|
rows |
GridDimension
|
the number of rows to build the automaton with. |
|
cols |
GridDimension
|
the number of columns to build the automaton with. |
|
stepFn |
stepFunction
|
a callback that will be used to calcualte the next state of each cell for each step the automaton takes. it's next state. |
|
renderFn |
renderFunction
|
a callback that will be used to render the state of each cell. |
|
s |
CellState
|
Array.<CellState>
|
initialisationFunction
|
<optional> |
the automaton's initial state. The state can be specified in three different ways:
|
Throws:
-
-
An error is thrown if the first five arguments are not present and valid, and if the sixth argument is present but not valid.
- Type
-
TypeError
-
-
-
An error is thrown if the table has already been initialised as an automaton.
- Type
-
Error
-
Members
(private) _$container :jQuerySingleContainer
A jQuery object representing the container for the automaton.
Type:
(private) _$table :jQuerySingleTable
A jQuery object representing the table that represents the automaton.
Type:
(private) _cols :GridDimension
The number of columns in the automaton. This property is forced to be a number before being stored.
Type:
(private) _grid :Array.<Array.<bartificer.ca.Cell>>
A 2D array of bartificer.ca.Cell objects representing the cells in the automaton.
Type:
-
Array.<Array.<bartificer.ca.Cell>>
(private) _renderFn :renderFunction
The callback used to style a given cell so it represents the appropriate state.
Type:
(private) _rows :GridDimension
The number of rows in the automaton. This property is forced to be a number before being stored.
Type:
(private) _stepFn :stepFunction
The callback used to calculate the next state of each cell each time the automaton steps forward.
Type:
Methods
$container() → {jQuerySingleContainer}
A read-only accessor function to access a reference to the jQuery object representing the container that holds the table that represents the automaton within the DOM.
Throws:
-
An error is thrown if the accessor is called with arguments.
- Type
-
Error
Returns:
- Type:
-
jQuerySingleContainer
$table() → {jQuerySingleTable}
A read-only accessor function to access a reference to the jQuery object representing the table that represents the automaton within the DOM.
Throws:
-
An error is thrown if the accessor is called with arguments.
- Type
-
Error
Returns:
- Type:
-
jQuerySingleTable
cell(x, y) → {bartificer.ca.Cell}
A function for accessing a given cell within the automaton.
Parameters:
Name | Type | Description |
---|---|---|
x |
GridCoordinate
|
the x coordinate of the requested cell. |
y |
GridCoordinate
|
the y coordinate of the requested cell. |
Throws:
-
-
A type error is thrown if invalid arguments are passed.
- Type
-
TypeError
-
-
-
A range error is thrown if either of the coordinates specify a cell who's coordiantes are beyond the edges of the automaton.
- Type
-
RangeError
-
cellState(x, y) → {CellState}
A function for accessing the current state of a given cell within the automaton.
Parameters:
Name | Type | Description |
---|---|---|
x |
GridCoordinate
|
the x coordinate of the requested cell. |
y |
GridCoordinate
|
the y coordinate of the requested cell. |
Throws:
-
-
A type error is thrown if invalid arguments are passed.
- Type
-
TypeError
-
-
-
A range error is thrown if either of the coordinates specify a cell who's coordiantes are beyond the edges of the automaton.
- Type
-
RangeError
-
Returns:
- Type:
-
CellState
cols() → {GridDimension}
A read-only accessor function to get the number of columns within the automaton.
Throws:
-
An error is thrown if the accessor is called with arguments.
- Type
-
Error
Returns:
- Type:
-
GridDimension
dimensions() → {Array.<number>}
A read-only accessor function to return both the width and height of the grid, i.e. the number of rows and columns.
Throws:
-
An error is thrown if the accessor is called with arguments.
- Type
-
Error
Returns:
- Type:
-
Array.<number>
An array of two numbers, the width (number of cols), and height (number of rows).
renderFunction() → {renderFunction}
A read-only accessor function to get a reference to the automaton's render function.
Throws:
-
An error is thrown if the accessor is called with arguments.
- Type
-
Error
Returns:
- Type:
-
renderFunction
rows() → {GridDimension}
A read-only accessor function to get the number of rows within the automaton.
Throws:
-
An error is thrown if the accessor is called with arguments.
- Type
-
Error
Returns:
- Type:
-
GridDimension
stepFunction() → {stepFunction}
A read-only accessor function to get a reference to the automaton's step function.
Throws:
-
An error is thrown if the accessor is called with arguments.
- Type
-
Error
Returns:
- Type:
-
stepFunction