lookup-grid
Position two-dimensional ndarrays on an row/col grid for lookup of individual coords and values.
npm
Install via$ npm install lookup-grid
API
var LookupGrid = var grid =
LookupGrid(rows, cols)
Create an instance with the specified shape as per rows
and cols
.
grid.set(row, col, array)
Place a 2 dimensional array (ndarray or array-grid) at origin [row, col]
.
If the same array (by ref) is placed multiple times, this moves the array instead of placing additional copies.
grid.remove(array)
Remove an array by ref from the grid.
grid.get(row,col)
Resolve the inner array and return the top most value at point [row, col]
.
grid.lookup(value)
Return the [row,col]
coordinates of the specified value using the origins supplied for the inner arrays.
Example
var ndarray = var ArrayGrid = // same API as ndarray but fixed at 2d var LookupGrid = var grid = var drums = console//|---|---|//| a | b |//|---|---|//| c | d |//|---|---|//| e | f |//|---|---| var synth = console//|---|---|---|//| k | l | m |//|---|---|---|//| h | i | j |//|---|---|---| var bass = // col majorconsole//|---|---|---|---|//| s | u | w | y |//|---|---|---|---|//| t | v | x | z |//|---|---|---|---| gridgridgrid console //= 'a'console //= 'd' console //= [0,0]console //= [0,1]console //= [7,3] console//|---|---|---|---|---|---|---|---|//| a | b | | k | l | m | | |//|---|---|---|---|---|---|---|---|//| c | d | | h | i | j | | |//|---|---|---|---|---|---|---|---|//| e | f | | | | | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | s | u | w | y | | |//|---|---|---|---|---|---|---|---|//| | | t | v | x | z | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---| // move the drums acrossgridconsole//|---|---|---|---|---|---|---|---|//| | a | b | k | l | m | | |//|---|---|---|---|---|---|---|---|//| | c | d | h | i | j | | |//|---|---|---|---|---|---|---|---|//| | e | f | | | | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | s | u | w | y | | |//|---|---|---|---|---|---|---|---|//| | | t | v | x | z | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---| // remove the synthgridconsole//|---|---|---|---|---|---|---|---|//| | a | b | | | | | |//|---|---|---|---|---|---|---|---|//| | c | d | | | | | |//|---|---|---|---|---|---|---|---|//| | e | f | | | | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | s | u | w | y | | |//|---|---|---|---|---|---|---|---|//| | | t | v | x | z | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---| // update inner arraydrumsdrumsconsole//|---|---|---|---|---|---|---|---|//| | % | b | | | | | |//|---|---|---|---|---|---|---|---|//| | c | d | | | | | |//|---|---|---|---|---|---|---|---|//| | $ | f | | | | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | s | u | w | y | | |//|---|---|---|---|---|---|---|---|//| | | t | v | x | z | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---| //// RECURSIVE var drums = var synth = var innerGrid = innerGridinnerGrid console var outerGrid = outerGrid console//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | | a | b | e | f | |//|---|---|---|---|---|---|---|---|//| | | | c | d | g | h | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|//| | | | | | | | |//|---|---|---|---|---|---|---|---|