These methods focus on determining the value and type of cells at a specific (row, col)
position:
- read(row, col): Returns the content of the cell at the specified
row
andcol
. - isEmpty(row, col): Checks if the specified cell at
row
andcol
is empty. - isFilled(row, col): Checks if the specified cell at
row
andcol
contains non-empty content. - isString(row, col): Determines if the specified cell at
row
andcol
contains a string. - isNumber(row, col): Determines if the specified cell at
row
andcol
contains a number. - isColor(row, col): Checks if the specified cell at
row
andcol
contains a color. - isImage(row, col): Checks if the specified cell at
row
andcol
contains an image. - isArray(row, col): Determines if the specified cell at
row
andcol
contains an array. - isFunction(row, col): Determines if the specified cell at
row
andcol
contains a function. - isObject(row, col): Determines if the specified cell at
row
andcol
contains an object.
Example #
(hover over a cell to view its contents)
code
let ps; // Image variable
let font; // Custom font
let quadrille;
let yellow, blue, red;
let value; // Checkbox for display toggle
function preload() {
// Load image and font in preload
ps = loadImage('/images/pola.jpg');
font = loadFont('/fonts/noto_sans.ttf');
}
function setup() {
createCanvas(6 * Quadrille.cellLength, 4 * Quadrille.cellLength, WEBGL);
textFont(font);
yellow = color('yellow');
blue = color('blue');
red = color('red');
// Quadrille containing cell functions and other content
quadrille = createQuadrille([
['hi', 100, ps, pulse, null, 0],
[null, yellow, pulse, ':)'],
[null, blue, pulse, 255, ':p'],
[null, red, null, 185, ';)', pulse]
]);
// Method to determine cell type
quadrille.cellType = function (row, col) {
if (this.isImage(row, col)) return `image`;
if (this.isNumber(row, col)) return `number`;
if (this.isColor(row, col)) return `color`;
if (this.isFunction(row, col)) return `function`;
if (this.isObject(row, col)) return `object`;
if (this.isString(row, col)) return `string`;
if (this.isArray(row, col)) return `array`;
if (this.isEmpty(row, col)) return `empty`;
};
// Method to determine cell value
quadrille.cellValue = function (row, col) {
return this.isFilled(row, col) ? this.read(row, col) : 'null';
};
// Create checkbox
value = createCheckbox('Display Value', false); // Default to false
value.position(10, height + 10); // Position checkbox
}
function draw() {
background('black');
// Draw q1
drawQuadrille(quadrille, { origin: CORNER });
// Interactive cell details for quadrille
displayCellDetails(quadrille);
}
function displayCellDetails(quadrille, offsetX = 0) {
const row = quadrille.mouseRow;
const col = quadrille.mouseCol;
// Check if row and col are within bounds
if (
row >= 0 && row < quadrille.height && // Row is within bounds
col >= 0 && col < quadrille.width // Column is within bounds
) {
const x = col * Quadrille.cellLength + offsetX - width / 2 + 5;
const y = row * Quadrille.cellLength - height / 2 + 15;
fill('magenta');
const prefix = `cell(${row}, ${col}) ${value.checked() ? 'value' : 'type'}:`;
const cellString = value.checked()
? quadrille.cellValue(row, col)
: quadrille.cellType(row, col);
text(`${prefix}\n${cellString}`, x, y);
}
}
function pulse() {
background('lime');
const l = Quadrille.cellLength / 2;
const radius = map(sin(frameCount * 0.1), -1, 1, 5, l);
noStroke();
fill('blue');
circle(0, 0, radius);
}
- This example builds on the createQuadrille(jagged_array) approach—check it out to understand the foundation.
- Dynamic Quadrille Methods: The
cellType
andcellValue
methods are appended to thequadrille
object, allowing runtime customization without requiring subclasses. These methods leverage most of the cell content accessors discussed in this section (is*
methods for type checking andread(row, col)
for value retrieval, respectively).- Positioning in
displayCellDetails
: Text positioning dynamically accounts for canvas centering and padding; abstracting this logic can simplify reuse.- Interactive Features: A checkbox toggles between displaying cell
type
orvalue
, while thepulse
function provides animated cell feedback.