Creates a quadrille of dimensions width × height and randomly places value in exactly order cells (clamped to the board size).

Example#

code
let quadrille;

function setup() {
  createCanvas(6 * Quadrille.cellLength, 4 * Quadrille.cellLength);
  quadrille = createQuadrille(6, 4, 13, 150);
}

function draw() {
  background('orange');
  drawQuadrille(quadrille);
}

The order argument means exactly what the order property means — the number of filled cells: after createQuadrille(6, 4, 13, 150), q.order === 13. Values beyond the board size clamp: createQuadrille(2, 2, 99, value) fills all 4 cells.

To define different values in createQuadrille(width, height, order, value), refer to createQuadrille(jagged_array).

Syntax#

createQuadrille(width, height, order, value)

Parameters#

ParamDescription
widthNumber: The total number of columns for the quadrille
heightNumber: The total number of rows for the quadrille
orderNumber: The number of cells to fill with value — the resulting order property (clamps to width × height)
value1Any: valid JavaScript value, with null representing empty cells

  1. A plain function value is stored, not called — it becomes a per-cell display routine ({ row, col, options }) => { ... } (see options). To have a function evaluated per cell at creation time — a fresh object or a varied tile per cell — tag it: Quadrille.factory(({ row, col }) => new Object(...))↩︎