ring(row, col, dimension, wrap)
Returns a new quadrille representing the square block of cells of radius dimension centered at (row, col) — the center cell included. Sugar over crop: crop(row - dimension, col - dimension, 2·dimension + 1, 2·dimension + 1, wrap). When wrap is true, indices wrap toroidally across borders; when false (default), out-of-bounds positions are treated as empty. The result has size (2·dimension + 1) × (2·dimension + 1).
Example
(click on canvas, move mouse and press keys 1 to 4)
Note
The ring includes its center, so on a filled center
ring(row, col).ordercounts the center too. The Minesweeper counting idiom —mines.ring(row, col).orderas the neighbor-mine count — works because it is computed only on empty centers; and since out-of-bounds pads as empty (crop semantics,wrap = false), edge cells simply count fewer neighbors, no special-casing needed.
Syntax
ring(row, col, [dimension = 1], [wrap = false])
Parameters
| Param | Description |
|---|---|
row |
Number: row index of the center cell [0..height] |
col |
Number: column index of the center cell [0..width] |
dimension |
Number: radius (≥ 0); the result is (2·dimension + 1)². Default is 1 |
wrap |
Boolean: when true, indices wrap toroidally at borders; when false (default), out-of-bounds cells are taken as empty |
What this page's examples use
- p5.quadrille
drawQuadrillecreateQuadrillecellLengthmouseRowmouseColrandwidthheightring- p5.js
createCanvasbackgroundcolortextkeypositioncreateCheckboxcheckedconstrainchanged
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.