tur/grid
grid-new
(grid-new [width height] :int)
allocate a zero-filled width x height GridCtx; focus starts at (0, 0).
| width | number of columns | |
| height | number of rows |
Since: Phase CA2
grid-get
(grid-get [g x y] :int)
read the cell value at (x, y); returns 0 for out-of-bounds coordinates.
| g | GridCtx handle from grid-new | |
| x | column index (0-based) | |
| y | row index (0-based) |
Since: Phase CA2
grid-set
(grid-set [g x y val] :int)
write val into cell (x, y) in-place; no-op if out of bounds.
| g | GridCtx handle from grid-new | |
| x | column index (0-based) | |
| y | row index (0-based) | |
| val | value to store |
Since: Phase CA2
grid-focus
(grid-focus [g] :int)
return the cell value at the current focus position (cx, cy).
| g | GridCtx handle from grid-new |
Since: Phase CA2
grid-width
(grid-width [g] :int)
return the number of columns in the grid.
| g | GridCtx handle from grid-new |
Since: Phase CA2
grid-height
(grid-height [g] :int)
return the number of rows in the grid.
| g | GridCtx handle from grid-new |
Since: Phase CA2
grid-cx
(grid-cx [g] :int)
return the current focus column index.
| g | GridCtx handle from grid-new |
Since: Phase CA2
grid-cy
(grid-cy [g] :int)
return the current focus row index.
| g | GridCtx handle from grid-new |
Since: Phase CA2
grid-clone
(grid-clone [g] :int)
deep-copy a grid, allocating a new GCtx and data array; cx/cy are preserved.
| g | GridCtx handle to clone |
Since: Phase CA2
grid-count-neighbors
(grid-count-neighbors [g] :int)
count live (non-zero) Moore 8-neighbours at the current focus.
| g | GridCtx handle; uses cx/cy as the center cell |
Since: Phase CA2
grid-print
(grid-print [g] :int)
print the grid to stdout as ASCII art ('#' = live, '.' = dead).
| g | GridCtx handle from grid-new |
Since: Phase CA2
Comonad[gridctx]
(definstance Comonad [gridctx])
Comonad instance for GridCtx (extract/extend/duplicate).
Since: Phase CA2
Internal definitions
__gridctx_extend-- comonad extend: produce a new grid by applying fn to each focused sub-grid.