Skip to main content

API

Classes

Grid
Grid3D
GridPoint

Members

createGridGrid

Create a grid

createGrid3DGrid3D
createPointGridPoint

Functions

getPoints()Array.<Array.<GridPoint>>

Get all the current points on the grid warning: gets the points array by reference. Changes to individual points will be reflected in the original grid object. To get a deep copy use grid.copy(). eg. grid.copy.get()

set()void

Replaces all the current points on the grid warning: sets a reference to the provided points. Changes in made by this grid object to the points will be reflected in the provided points array.

getPoint(col, row)GridPoint

Gets a point from from indeces [col, row]

getFlat()Array.<GridPoint>

returns a one dimensional array of GridPoints of the grid. One column pushed after the other.

draw(func, condition)Grid

Loops over the points in the grid, passing each point to the provided func parameter Provide a drawing function

every(func, condition)Grid

Loops over the points in the grid, passing each point to the provided func parameter

transform(func, condition)Grid

Transforms x, y values of points on the grid using the supplied transform function. control which points are getting affected by supplying a condition

translate(x, y, [condition])Grid

Translates the entire grid by x en y coordinates

copy()Grid

Creates a deep copy of the current grid object

setPoint(col, row, layer, point)
every(func, condition)Grid3D

Loops over the points in the grid, passing each point to the provided func parameter

transform(func, condition)Grid3D

Transforms x, y, z values of points on the grid using the supplied transform function. control which points are getting affected by supplying a condition

Grid

Kind: global class

new Grid(cols, rows, width, height, [shape])

The main Grid class containing all a two dimensional array of GridPoints and methods to manipulate the GridPoints on grid.

ParamTypeDescription
colsnumberthe amount of columns the grid needs to contain
rowsnumberthe amount of rows the grid needs to contain
widthnumberthe width of the grid
heightnumberthe height of the grid
[shape]GridShapethe shape of the grid (RECTANGLE or ELLIPSE). Defaults to a rectangular shaped grid.

Grid3D

Kind: global class

new Grid3D(cols, rows, layers, width, height, depth)

The main Grid class containing all a two dimensional array of GridPoints and methods to manipulate the GridPoints on grid.

ParamTypeDescription
colsnumberthe amount of columns the grid needs to contain
rowsnumberthe amount of rows the grid needs to contain
layersnumberthe amount of layers the grid needs to contain
widthnumberthe width of the grid
heightnumberthe height of the grid
depthnumberthe depth of the grid

GridPoint

Kind: global class
Properties

NameTypeDescription
xnumberthe x coordinate of the point
ynumberthe y coordinate of the point
znumberthe y coordinate of the point

new GridPoint(x, y, [z])

Represent a single point on the grid.

ParamTypeDescription
xnumberthe x coordinate of the point
ynumberthe y coordinate of the point
[z]numberthe y coordinate of the point

createGrid ⇒ Grid

Create a grid

Kind: global variable

ParamType
optionsGridOptions

Example

const grid = createGrid({cols: 3, rows: 5, width 1080, height: 1080});

createGrid3D ⇒ Grid3D

Kind: global variable

Param
options

Example

const grid = createGrid({cols: 3, rows: 5, layers: 8 , width 1080, height: 1080, depth: 1080});

createPoint ⇒ GridPoint

Kind: global variable
Returns: GridPoint - a point on a the x, y, z plane. Can be set to a specific index on the grid using the Grid or Grid3D setPoint methods

Param
x
y
z

Example

// Create and set a point on a grid
const grid = createGrid({cols:5, rows: 8, width 1920, height: 1080});
const firstPoint = createPoint(-10, -10);
grid.setPoint(0, 0, firstPoint);

GridShape : enum

Enum used to determine the grid shape in the Grid constructor. Values: RECTANGLE or ELLIPSE.

Kind: global enum
Read only: true

getPoints() ⇒ Array.<Array.<GridPoint>>

Get all the current points on the grid warning: gets the points array by reference. Changes to individual points will be reflected in the original grid object. To get a deep copy use grid.copy(). eg. grid.copy.get()

Kind: global function

set() ⇒ void

Replaces all the current points on the grid

warning: sets a reference to the provided points. Changes in made by this grid object to the points will be reflected in the provided points array.

Kind: global function

getPoint(col, row) ⇒ GridPoint

Gets a point from from indeces [col, row]

Kind: global function

ParamTypeDescription
colnumberthe col index
rownumberthe row index

getFlat() ⇒ Array.<GridPoint>

returns a one dimensional array of GridPoints of the grid. One column pushed after the other.

Kind: global function

draw(func, condition) ⇒ Grid

Deprecated

Loops over the points in the grid, passing each point to the provided func parameter Provide a drawing function

Kind: global function
Returns: Grid - returns @this Grid Object. Used for chaining Grid methods

ParamTypeDescription
funcGridFunctiona function that handles drawing of each individual point
conditionConditionan optional condition for which points to draw

every(func, condition) ⇒ Grid

Loops over the points in the grid, passing each point to the provided func parameter

Kind: global function
Returns: Grid - returns @this Grid Object. Used for chaining Grid methods

ParamTypeDescription
funcGridFunctiona function to access each point and row/col indices
conditionConditionan optional condition for which points to execute func over

transform(func, condition) ⇒ Grid

Transforms x, y values of points on the grid using the supplied transform function. control which points are getting affected by supplying a condition

Kind: global function
Returns: Grid - returns @this Grid Object. Used for chaining Grid methods

  • @example // Translates the grid on the x-axis by 5 and on the y-axis by 8 grid.transform((point) => { point.x += 5; point.y += 8; return point; // Make sure to return the transformed point })
ParamTypeDescription
funcTransformFunctiona function to transform the point's x, y values. Must return the transformed point.
conditionConditionan optional condition for which points to be affected

translate(x, y, [condition]) ⇒ Grid

Translates the entire grid by x en y coordinates

Kind: global function
Returns: Grid - returns @this Grid Object. Used for chaining Grid methods

ParamTypeDescription
xnumberthe x coordinates to translate the points with
ynumberthe y coordinates to translate the points with
[condition]Conditionan optional condition for which points to translate

copy() ⇒ Grid

Creates a deep copy of the current grid object

Kind: global function
Returns: Grid - a new instance of Grid of with the same coordinate values as @this Grid

setPoint(col, row, layer, point)

Kind: global function

Param
col
row
layer
point

Example

// Create and set a point on a grid
const grid = createGrid({cols: 3, rows: 5, layers: 8 , width 1080, height: 1080, depth: 1080});
const firstPoint = createPoint(-540, -540, -540);
grid.setPoint(0, 0, 0, firstPoint);

every(func, condition) ⇒ Grid3D

Loops over the points in the grid, passing each point to the provided func parameter

Kind: global function
Returns: Grid3D - returns @this Grid3D Object. Used for chaining Grid methods

ParamTypeDescription
funcGridFunctiona function to access each point and row/col indices
conditionConditionan optional condition for which points to execute func over

Example

// draw a spheres on the grid where the size depends on the position on the grid
// sphere is a pseudo function to draw spheres to a html canvas.
grid.every((point, col, row, layer) => {
const radius = (col + row + layer + 1) * 5;
sphere(point.x, point.y, point.z, radius);
})

transform(func, condition) ⇒ Grid3D

Transforms x, y, z values of points on the grid using the supplied transform function. control which points are getting affected by supplying a condition

Kind: global function
Returns: Grid3D - returns @this Grid3D Object. Used for chaining Grid methods

ParamTypeDescription
funcTransformFunctiona function to transform the point's x, y values. Must return the transformed point.
conditionConditionan optional condition for which points to be affected

Example

// Translates the grid on the y-axis by 10 and on the z-axis by 5
grid.transform((point) => {
point.y += 10;
point.z += 5;
return point; // Make sure to return the transformed point
})