filter
Filters which cells to draw from a given quadrille q. It accepts the following types:
A value collection (
ArrayorSet) Draws only the cells whose values are included in the collection. Example:drawQuadrille(q, { filter: [tomato, skyblue] })A predicate function over the cell (
(cell) => boolean) The function receives{ row, col, value }and must returntrueto draw that cell. Example:drawQuadrille(q, { filter: ({ value }) => brightness(value) < 50 })A single value (anything that is neither a function nor a collection) Draws only the cells whose value matches it by identity (
===):drawQuadrille(q, { filter: tomato })
Note
Arrow functions offer a compact syntax. For instance, the predicate
function (cell) { return brightness(cell.value) < 50; }becomes:
cell => brightness(cell.value) < 50;You can also destructure to focus only on what you need:
({ value }) => brightness(value) < 50;
Example: Filtering by Value Collection
(click on canvas and press any key to randomize q)
Note
The
valuesarray must contain references to the exact instances used to fill the quadrille. For example, ifqwas filled with the variableyellow = color('lemonchiffon'), thenvaluesmust include that same variable, not a newcolor('lemonchiffon').
Example: Filtering by Predicate Value
(click on canvas and press any key to randomize q)
Note
The method
q.visit(callback)iterates over all cells in row-major order, invokingcallback({ row, col, value })for each one. Use destructuring (e.g.,{ value }) when you only need part of the cell.
Note
In JavaScript,
for...inis used to iterate over object keys, typically for plain objects likefilters:for (const label in filters) { select.option(label); }
Example: Filtering by Predicate Value, Row, and Column
(click on canvas and press any key to randomize q)
Syntax
drawQuadrille(quadrille, { filter })
Parameters
| Param | Description |
|---|---|
filter |
Specifies which cells to draw. All cells are drawn if omitted or undefined. It can be:
|
What this page's examples use
- p5.quadrille
drawQuadrillecreateQuadrillecellLengthfillvisitrandomizeoutlineWeightoutline- p5.js
createCanvasbackgroundcolorvaluerandomcreateCheckboxcreateSelectcheckedoptionblueredbrightnesssaturation- JavaScript
Array.push
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.