tur/grid

stdlib/grid.tur
defn

grid-new

(grid-new [width height] :int)

allocate a zero-filled width x height GridCtx; focus starts at (0, 0).

widthnumber of columns
heightnumber of rows

Since: Phase CA2

defn

grid-get

(grid-get [g x y] :int)

read the cell value at (x, y); returns 0 for out-of-bounds coordinates.

gGridCtx handle from grid-new
xcolumn index (0-based)
yrow index (0-based)

Since: Phase CA2

defn

grid-set

(grid-set [g x y val] :int)

write val into cell (x, y) in-place; no-op if out of bounds.

gGridCtx handle from grid-new
xcolumn index (0-based)
yrow index (0-based)
valvalue to store

Since: Phase CA2

defn

grid-focus

(grid-focus [g] :int)

return the cell value at the current focus position (cx, cy).

gGridCtx handle from grid-new

Since: Phase CA2

defn

grid-width

(grid-width [g] :int)

return the number of columns in the grid.

gGridCtx handle from grid-new

Since: Phase CA2

defn

grid-height

(grid-height [g] :int)

return the number of rows in the grid.

gGridCtx handle from grid-new

Since: Phase CA2

defn

grid-cx

(grid-cx [g] :int)

return the current focus column index.

gGridCtx handle from grid-new

Since: Phase CA2

defn

grid-cy

(grid-cy [g] :int)

return the current focus row index.

gGridCtx handle from grid-new

Since: Phase CA2

defn

grid-clone

(grid-clone [g] :int)

deep-copy a grid, allocating a new GCtx and data array; cx/cy are preserved.

gGridCtx handle to clone

Since: Phase CA2

defn

grid-count-neighbors

(grid-count-neighbors [g] :int)

count live (non-zero) Moore 8-neighbours at the current focus.

gGridCtx handle; uses cx/cy as the center cell

Since: Phase CA2

defn

grid-print

(grid-print [g] :int)

print the grid to stdout as ASCII art ('#' = live, '.' = dead).

gGridCtx handle from grid-new

Since: Phase CA2

definstance

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.