Cell

bartificer.ca. Cell

Fcnew Cell($td, x, y, sopt)

A prototype to represent a single cell within a cellular automaton. The cell will be represented within the DOM by a single table data cell.

The constructor expects to be passed a table data cell, and that cell will be emptied of all content. The class bartificer-ca-cell will be added to the data cell, and a reference to the constructed object will be added to the data cell as the data attribute data-bartificer-object (bartificerObject from JavaScipt's point of view).

Parameters:
Name Type Attributes Description
$td jQuerySingleTD

A jQuery object representing the table data cell that will represent the new cell within the automaton.

x GridCoordinate

the cell's x coordinate within the automaton.

y GridCoordinate

the cell's y coordinate within the automaton.

s CellState <optional>

the cell's initial state.

Throws:
  • An error is thrown if the first three arguments are not present and valid.

    Type
    TypeError
  • An error is thrown if the table data cell has already been initialised as a cell within an automaton.

    Type
    Error

Methods

F$td() → {jQuerySingleTD}

A read-only accessor function to access a reference to the jQuery object representing the table data cell that represents the cell within the DOM.

Throws:

An error is thrown if the accessor is called with arguments.

Type
Error
Returns:
Type:
jQuerySingleTD

Fadvance()

Advance the cell to its next state.

Throws:

An error is thrown if an attempt is made to advance while there is no next state defined.

Type
Error
Returns:

a reference to self to facilitate function chaining.

Fcoordinates() → {Array}

A read-only accessor function to access the cell's x and y coordinates within the automaton.

Throws:

An error is thrown if the accessor is called with arguments.

Type
Error
Returns:
Type:
Array

An array of length two with the x coordinate as the first value and the y coordinate as the second.

FhasNextState() → {boolean}

Function to determine whether or not the cell has a next state defined.

Returns:
Type:
boolean

true if the cell has a next state defined, false otherwise.

FnextState(nsopt) → {CellState|undefined}

Accessor function for the cell's next state. Always returns the next state of the cell. If an argument is passed, the next state is updated to that value and then returned.

Parameters:
Name Type Attributes Description
ns CellState | undefined <optional>

if passed, the next state of the cell is set to this value. undefined indicates that the cell has no next state.

Throws:

If an argument is passed and it's not value, an error is thrown.

Type
TypeError
Returns:
Type:
CellState | undefined

When the cell has a next state that's returned, otherwise undefined is returned.

Fstate() → {CellState|undefined}

A read-only accessor function to access the cell's current state, if any.

Throws:

An error is thrown if the accessor is called with arguments.

Type
Error
Returns:
Type:
CellState | undefined

When the cell has a current state that's returned, otherwise undefined is returned.

Fx() → {GridCoordinate}

A read-only accessor function to access the cell's x coordinate within the automaton.

Throws:

An error is thrown if the accessor is called with arguments.

Type
Error
Returns:
Type:
GridCoordinate

Fy() → {GridCoordinate}

A read-only accessor function to access the cell's y coordinate within the automaton.

Throws:

An error is thrown if the accessor is called with arguments.

Type
Error
Returns:
Type:
GridCoordinate