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

edit, then run

Note

Observation about images Images are loaded in the async setup function using await with loadImage to ensure they are fully available before being used.

Example 2: Videos, Text, Colors, Numbers, and Emojis

(click to toggle the video playback)

edit, then run

Note

Observations about video

  1. Loading the Video: Videos are loaded in the async setup() function with await and immediately hidden using the destino hide method to remove default controls.
  2. Interactive Playback Toggle: This code toggles the video playback when the mouse is clicked:
    destino.looping ? destino.pause() : destino.loop();
    destino.looping = !destino.looping;
    The ternary operator (condition ? exprIfTrue : exprIfFalse) is shorthand for if/else. Equivalent code:
    if (destino.looping) destino.pause();
    else destino.loop();
  3. destino.looping custom property: Initially, destino.looping is undefined (a falsy value). The line destino.looping = !destino.looping; flips its value to true on the first click, and subsequently toggles it between true and false.

Example 3: Functions, Images, Text, Colors and Emojis

edit, then run

Note

Observations about P2D mode and function cells

  1. Canvas Mode and Function Cells: Using P2D mode—either by omitting the third argument to createCanvas() or explicitly setting it—supports 2D function-based cells like pulse.
  2. Origin in the Canvas: In P2D mode, 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, use drawQuadrille(quadrille, { origin: CENTER }).
  3. 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 (like circle(center, center, radius)), define center = Quadrille.cellLength / 2. Alternatively, pass options: { origin: CENTER } to drawQuadrille() to shift the coordinate system to the cell center.

Example 4: WEBGL Mode with Functions, Images, Text, and Colors

edit, then run

Note

Observations about WEBGL mode and function cells

  1. 3D Function Cells: Using WEBGL mode as the third argument to createCanvas() enables 3D function-based cells like ringTorus, which can render geometry using primitives such as box, sphere, and torus.
  2. Font Limitations: In WEBGL mode, fonts must be loaded manually, and emojis are not supported (the only known limitation).
  3. Origin in the Canvas: In WEBGL mode, the canvas origin defaults to the center. To align the top-left of the quadrille with the canvas, use drawQuadrille(quadrille, { origin: CORNER }).
  4. 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, pass options: { origin: CORNER } to drawQuadrille().

Example 5: p5.Graphics, Images, Text, Colors, and Emojis

edit, then run

Note

Observations about p5.Graphics cells

  1. Alternative to function cells: p5.Graphics can be used instead of function cells and works in both P2D and WEBGL modes, but the resulting code is less clean compared to function cells.
  2. Requires a separate p5.Graphics object: A p5.Graphics object (pg) must be created using createGraphics, usually with dimensions matching the cell size.
  3. Origin in P2D mode: In this example, the origin is the top-left corner, so pg.circle(pg.width / 2, pg.height / 2, radius) centers the circle within the cell.
  4. Manual update trigger: p5.Graphics requires an explicit update call, such as from draw, which makes it less concise than function cells.
  5. Performance: p5.Graphics is 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
drawQuadrille createQuadrille cellLength
p5.js
createCanvas background color loadImage fill noStroke map frameCount circle pop push colorMode createGraphics sin textFont createVideo hide loadFont rotateY WEBGL ambientLight directionalLight HSB rotateX torus

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.