drawQuadrille(args)

The drawQuadrille function is used to render a quadrille onto the canvas or a specified graphics buffer. It provides various parameters for customizing the appearance and behavior of the drawn quadrille, including cell dimensions, colors, and display styles. It also accepts a raw 1D/2D JS array, wrapped on the fly as a live zero-copy view — see drawing arrays.

By default, drawQuadrille(quadrille) is sufficient for most cases where no custom display parameters are needed, as it uses the quadrille's default properties for rendering. For more advanced use cases, drawQuadrille(quadrille, { options }) allows you to specify optional display parameters, such as cellLength, outline, textColor, and more, to customize the rendering behavior.

Configuration

The drawQuadrille function simplifies customization by using its { options } object literal parameter, leveraging JavaScript object destructuring to extract values directly. This approach makes function calls more readable, flexible, and maintainable, allowing you to configure only the parameters you need while relying on defaults for the rest.

Example

drawQuadrille(quadrille, {
  cellLength: 50,   // Custom size for each cell
  outline: 'blue',  // Edge color of the quadrille
  outlineWeight: 2, // Line thickness for the outline
  textColor: 'white', // Color for text inside cells
  textZoom: 0.5,    // Scale the text in cells
});

In this example, only these parameters are explicitly configured:

  • cellLength: Specifies the size of each cell in pixels.
  • outline: Sets the edge color of the quadrille.
  • outlineWeight: Defines the thickness of the outline.
  • textColor: Controls the color of any text rendered in the quadrille cells.
  • textZoom: Scales the size of the text rendered in the cells.

The remaining parameters in the { options } object use their default values, making it easier to adjust specific aspects of the quadrille's rendering without needing to pass every option explicitly.

Note

JavaScript object destructuring allows extracting values directly from objects, improving code clarity and ease of use. This approach provides several benefits:

  1. Clarity: Parameters are grouped into a single, descriptive object, making function calls easier to read.
  2. Flexibility: Only the parameters you need are specified, while defaults handle the rest.
  3. Order Independence: Parameters are assigned based on their names, so their order doesn’t matter.
  4. Extensibility: New parameters can be added without breaking existing function calls.

Syntax

drawQuadrille(quadrille, [{[cellLength], [outline], [outlineWeight], [textColor], [textZoom], [textFont], [x], [y], [row], [col], [filter], [graphics], [origin], [options], [tileDisplay], [stringDisplay], [numberDisplay], [bigintDisplay], [booleanDisplay], [colorDisplay], [imageDisplay], [functionDisplay], [arrayDisplay], [objectDisplay], [symbolDisplay]}])

Parameters

param description
quadrille Quadrille | Array: The quadrille to be drawn — or a raw 1D/2D array, wrapped on the fly as a live zero-copy view (see drawing arrays)
cellLength Number: Edge length in pixels. Default is Quadrille.cellLength
outline p5.Color: Edge color. Default is Quadrille.outline
outlineWeight Number: Edge weight. Default is Quadrille.outlineWeight
textColor p5.Color: Text color. Default is Quadrille.textColor
textZoom Number: Text zoom level. Default is Quadrille.textZoom
textFont p5.Font: Specifies the font used for rendering text in cells. Default is the current p5.js font
x Number: Upper-left quadrille pixel x-coordinate. Default is 0. Takes precedence over col
y Number: Upper-left quadrille pixel y-coordinate. Default is 0. Takes precedence over row
row Number: Upper-left quadrille row. Default is 0
col Number: Upper-left quadrille column. Default is 0
filter Specifies which cells to draw. All cells are drawn if this parameter is omitted or undefined. It can be:
  • a value collection (Array or Set)
  • a predicate function (value => boolean)
  • an object with optional value, row, and/or col predicates
graphics p5.Graphics: Renderer target. Default is this (main canvas)
origin Constant: Defines the reference point for drawing the quadrille. CORNER aligns it to the top-left corner of the canvas (default in P2D), and CENTER aligns it to the center of the canvas (default in WEBGL)
options Object: Forwarded as the sole argument to functions stored in cells and to object cells' display methods, carrying origin plus the current cell's row and col. Default is a fresh {} per call
tileDisplay1 Function: Renders cell contours. Default is Quadrille.tileDisplay
stringDisplay Function: Renders strings in cells. Default is Quadrille.stringDisplay
numberDisplay Function: Renders numbers in cells as grayscale values. Default is Quadrille.numberDisplay
bigintDisplay Function: Renders BigInt values using numberDisplay. Default is Quadrille.bigintDisplay
booleanDisplay Function: Renders boolean values as ✅ or ❎. Default is Quadrille.booleanDisplay
colorDisplay Function: Renders colors in cells. Default is Quadrille.colorDisplay
imageDisplay Function: Renders images in cells. Default is Quadrille.imageDisplay
functionDisplay Function: Renders functions in cells, in both P2D and WEBGL (via a framebuffer in WEBGL). Default is Quadrille.functionDisplay
arrayDisplay Function: Renders cells filled with arrays. No static default provided
objectDisplay Function: Renders cells filled with objects. No static default provided
symbolDisplay Function: Renders cells filled with symbols. No static default provided
  1. The tileDisplay parameter allows implementing other regular tilings beyond the default square tiling. ↩

19 pages

Quadrille.cellLength

Quadrille.outline

Quadrille.outlineWeight

Quadrille.textColor

Quadrille.textZoom

Quadrille.thinWall

textFont

x & y

row & col

filter

graphics

origin

display functions

options

drawing arrays

Quadrille.darkSquare

Quadrille.lightSquare

Quadrille.chessSymbols

Quadrille.chessKeys

What this page's examples use
p5.quadrille
drawQuadrille

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.