replace(value)

Replaces all filled cells in the quadrille with the specified value — empty cells are untouched: the exact complement of fill(value), which touches only empties. Chained, they two-tone a board totally: q.replace(red).fill(green) turns every filled cell red and every empty cell green. Returns the quadrille (chainable).

Example

(click or press any key to toggle between replacing cells and resetting)

edit, then run

Note

Like fill(value), a non-factory value is stored as one shared instance across all replaced cells — see the identity note there: it is what makes the replaced region strict-searchable and floodable as one.

Syntax

replace(value)

Parameters

Param Description
value1 Any: A valid JavaScript value
  1. A plain function value is stored, not called — it becomes a per-cell display routine ({ row, col, options }) => { ... } (see options). To have a function evaluated per cell at replace time — a fresh object or a varied tile per cell — tag it: Quadrille.factory(({ row, col }) => new Object(...)). ↩
What this page's examples use
p5.quadrille
drawQuadrille createQuadrille cellLength rand replace
p5.js
createCanvas background color

Names the analysis can prove are called, and the line each one is documented on. Local variables and members of an unknown receiver are left out.