Extends :: Obj

A class that defines a grid at a given position with a number or rows, columns, and a cell resolution. The position vector pos is at the top-left corner of an Grid.

This class must be accessed through the iio package.



These functions are used to instantiate new instances of the Grid class. Constructor functions must be preceded by the new keyword.

iio.Grid( Vector pos, Number: columns, rows, xRes, yRes )

iio.Grid( Number: x1, y1, columns, rows, xRes, yRes )

- creates a grid at the given vector with the given properties.

- xRes and yRes refer to the resolution of a cell (in pixels). If yRes is unspecified, the grid will have square cells with xRes as their size.

- the default value for any undefined parameter (except yRes when xRes exists) is 0.

//create 10x10 grid with 20x22 cells
var grid = new iio.Grid(0,0,10,10,20,22);

//create 3x4 grid with 50x50 cells
var grid2 = new iio.Grid(0,0,3,4,50);

Inherited Properties

Grid :: Obj

Obj.pos :: ioVec

Obj.rotation :: Number


Graphics Properties

The following properties can are attached by the iio Graphics Engine. Note that these properties are 'undefined' by default, so you must define them with their set functions or set their values directly.

.styles.alpha :: Number

.styles.strokeStyle :: Color||Pattern||Gradient

.styles.lineWidth :: Number

.styles.shadow :: Object

.styles.fxFade :: Object



The new data added by the Grid class.


.cells :: Vec

- a matrix representing the coordinates of this grid. Cells are indexed as [row][column].

//get a grids first cell
var cell0 = grid.cells[0][0];

//add a property called 'impassible'
//to the top row of grid cells
for (var c=0; c<grid.C; c++)
  grid.cells[0][c].impassible = true;

.R :: Number

- the number of rows in this grid

//get the number of rows
var r = grid.R;

.C :: Number

- the number of columns in this grid

//get the number of rows
var c = grid.C;

.res :: Vec

- a vector defining this grids cell resolution.

//get the cell resolution
var xRes = grid.res.x;
var yRes = grid.res.y;

Inherited Functions

Grid :: Obj





Graphics Functions

The following functions can are attached by the iio Graphics Engine.



These functions are added by the Grid class, and available to all instantiated Grid objects.



:: Returns Grid

- returns a new Grid with the same properties as this one. Makes a hard copy of the object.

//clone a grid
var gridClone = grid.clone();


:: Returns this

- recreates this grids cells array. All properties previously set will be erased from the structure.

//reset grid cells

.getCellAt( Vector v )

.getCellAt( Number: x, y )

:: Returns Vec

- returns a vector with the coordinates of the cell that contains the given position.

- if the given position is contained in the grid, this function will return false.

//get the cell at canvas center
var c = grid.getCellAt(

.getCellCenter( Vector v, Boolean pixelPos )

.getCellCenter( Number: x, y, Boolean pixelPos )

:: Returns Vec

- returns the center position of the cell of interest.

- pixelPos is a flag to indicate if the given coordinate is a absolute position on the canvas or an index set to this grid's cell structure. The default value for this parameter is false

//get the center of cell 1,1
var c = grid.getCellCenter(1,1)

//get the center of whichever
//cell contains the coordinate 50x50
var c = grid.getCellCenter(50,50,true);