visit(callback, predicate)

Iterates cells in row-major order and calls callback({ row, col, value }) for each cell where predicate({ row, col, value }) returns true. Reading and mutating the grid inside the callback is allowed.

Example

(move mouse to highlight 🐸 filled cells in the hovered col, and click to randomize q)

edit, then run

Note

  • The predicate decides which cells are visited (e.g., only 🐸 in the current column).
  • The callback defines what to do with those visited cells (e.g., fill them with semi-transparent color).

Syntax

visit(callback, predicate)

Parameters

Param Description
callback Function called for each visited cell, receiving an object { row, col, value }. Its return value is ignored
predicate A function ({ row, col, value }) => boolean. Only cells for which the predicate returns true are visited
What this page's examples use
p5.quadrille
drawQuadrille createQuadrille cellLength mouseCol fill visit randomize
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.