createQuadrille(jagged_array)
The createQuadrille function creates a quadrille and fills its cells using items from a jagged_array. The array can contain any combination of valid JavaScript values, with null representing empty cells. Rows may have different lengths — shorter rows are padded with null to the longest row's width — and holes or explicit undefined entries likewise normalize to null on entry.
Example 1: Images, Text, Colors, Numbers, and Emojis
Note
Observation about images Images are loaded in the
asyncsetup function usingawaitwith loadImage to ensure they are fully available before being used.
Example 2: Videos, Text, Colors, Numbers, and Emojis
(click to toggle the video playback)
Note
Observations about video
- Loading the Video: Videos are loaded in the
asyncsetup()function withawaitand immediately hidden using thedestinohide method to remove default controls.- Interactive Playback Toggle: This code toggles the video playback when the mouse is clicked:
The ternary operator (destino.looping ? destino.pause() : destino.loop(); destino.looping = !destino.looping;condition ? exprIfTrue : exprIfFalse) is shorthand forif/else. Equivalent code:if (destino.looping) destino.pause(); else destino.loop();destino.loopingcustom property: Initially,destino.loopingisundefined(a falsy value). The linedestino.looping = !destino.looping;flips its value totrueon the first click, and subsequently toggles it betweentrueandfalse.
Example 3: Functions, Images, Text, Colors and Emojis
Note
Observations about P2D mode and function cells
- Canvas Mode and Function Cells: Using
P2Dmode—either by omitting the third argument tocreateCanvas()or explicitly setting it—supports 2D function-based cells likepulse.- Origin in the Canvas: In
P2Dmode, the canvas origin defaults to the top-left corner. To position the entire quadrille with its top-left corner at the center of the canvas, usedrawQuadrille(quadrille, { origin: CENTER }).- Origin in Function Cells: Likewise, within each function cell (such as
pulse), the coordinate origin is also the top-left corner of the cell. To draw shapes centered within the cell (likecircle(center, center, radius)), definecenter = Quadrille.cellLength / 2. Alternatively, passoptions: { origin: CENTER }todrawQuadrille()to shift the coordinate system to the cell center.
Example 4: WEBGL Mode with Functions, Images, Text, and Colors
Note
Observations about WEBGL mode and function cells
- 3D Function Cells: Using
WEBGLmode as the third argument tocreateCanvas()enables 3D function-based cells likeringTorus, which can render geometry using primitives such asbox,sphere, andtorus.- Font Limitations: In
WEBGLmode, fonts must be loaded manually, and emojis are not supported (the only known limitation).- Origin in the Canvas: In
WEBGLmode, the canvas origin defaults to the center. To align the top-left of the quadrille with the canvas, usedrawQuadrille(quadrille, { origin: CORNER }).- Origin in Function Cells: Likewise, within each function cell (such as
ringTorus), the coordinate origin is also the center of the cell. To draw from the top-left corner instead, passoptions: { origin: CORNER }todrawQuadrille().
Example 5: p5.Graphics, Images, Text, Colors, and Emojis
Note
Observations about p5.Graphics cells
- Alternative to function cells:
p5.Graphicscan be used instead of function cells and works in bothP2DandWEBGLmodes, but the resulting code is less clean compared to function cells.- Requires a separate p5.Graphics object: A
p5.Graphicsobject (pg) must be created usingcreateGraphics, usually with dimensions matching the cell size.- Origin in P2D mode: In this example, the
originis the top-left corner, sopg.circle(pg.width / 2, pg.height / 2, radius)centers the circle within the cell.- Manual update trigger:
p5.Graphicsrequires an explicit update call, such as fromdraw, which makes it less concise than function cells.- Performance:
p5.Graphicsis less efficient than function cells, which are more performant.
Warning
Function cells are the preferred choice in this API's examples while occasionally using
p5.Graphics.
Syntax
createQuadrille(jagged_array)
Parameters
| Param | Description |
|---|---|
jagged_array |
An array of rows, possibly of different lengths, containing any combination of valid JavaScript values. Use null to represent empty cells (short rows pad with null; holes and undefined normalize to null) |
What this page's examples use
- p5.quadrille
drawQuadrillecreateQuadrillecellLength- p5.js
createCanvasbackgroundcolorloadImagefillnoStrokemapframeCountcirclepoppushcolorModecreateGraphicssintextFontcreateVideohideloadFontrotateYWEBGLambientLightdirectionalLightHSBrotateXtorus
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.