new Grid(width, height, opts)
Creates a new two dimensional array
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
width |
number | The width of the Grid |
|||||||||
height |
height | The height of the Grid |
|||||||||
opts |
object | Options Properties
|
Members
-
dataBuf
-
A Uint8Array for the raw data underlying the Grid
-
height
-
How tall the Grid is
-
width
-
How wide the Grid is
Methods
-
static diff(src, dst) → {Array.<object>|null}
-
Compares two Grids and returns an Array of the differences. Grids must be the same height and width.
Parameters:
Name Type Description src
Grid The first grid to compare.
dst
Grid The second grid to compare.
Returns:
Array.<object> | null -An Array of Objects describing the differences. Object for each change is
{x, y, srcVal, dstVal}
. Returnsnull
if there are no differences. -
static from(val)
-
Creates a new Grid from an Array of strings.
Parameters:
Name Type Description val
Array.<string> An array of equal length strings to set the initial value of the Grid. The Grid height will be equal to the number of elements in the array, and the width will be equal to the length of the strings.
-
clear()
-
Resets all data in the Grid to zero.
-
copy() → {Grid}
-
Creates a copy of the Grid with the same values but different underlying data.
-
forEach(cb)
-
Iterates all the cells of the Grid
Parameters:
Name Type Description cb
function Called for each cell of the Grid. Signature is
cb(value, x, y, grid)
. -
toString() → {string}
-
Convert the Grid to a human-readable string. If
converter
was specified as an option during construction, it is used to convert each element.Returns:
string -A human-readable string representing the Grid.