fill(row, col, value, directions)
Fills a specific cell and all connected cells holding the same value as it with value, spreading in 4 or 8 directions via flood fill — flooding from an empty cell paints the connected empty region, the classic paint bucket.
Example
(click on any cell to perform flood fill based on selected directions; press any key to reset)
Note
Connected means same value, and sameness is identity (
===) — the flood spreads through cells matching the start cell's value and stops at anything else; see clear(row, col, directions) for the identity note in full. Filling a region with the value it already holds is a no-op.
Syntax
fill(row, col, value, directions)
Parameters
| Param | Description |
|---|---|
row |
Number: row index of the cell to start filling [0..height] |
col |
Number: column index of the cell to start filling [0..width] |
value1 |
Any: A valid JavaScript value |
directions |
Number: Number of directions for flood fill (4 or 8), default is 4 |
What this page's examples use
- p5.quadrille
drawQuadrillecreateQuadrillecellLengthmouseRowmouseColrandfill- p5.js
createCanvasbackgroundcolorvaluecreateSelectoptionselected
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.