rand()
#
Use value
to randomly fill (or clear if value
is null
) cells the specified number of times
.
Examples #
(numeric keys define times
while others define value
, c sets it as null
)
code
Quadrille.cellLength = 30;
let times = 5;
let value, values;
let quadrille;
let p;
function setup() {
createCanvas(12 * Quadrille.cellLength, 12 * Quadrille.cellLength);
values = ['👻', '✈️', null, color('cyan'), 125, '🐒', '🐍'];
value = '🐒';
quadrille = createQuadrille(12, 12, times, value);
p = createP();
p.html('mouse click: ' + (value === null ? 'clears ' + times + ' time(s)'
: 'fills ' + times + ' time(s) with ' + value));
p.style('font-size', '16px');
p.position(10, height);
}
function draw() {
background('yellow');
drawQuadrille(quadrille);
}
function mouseClicked() {
quadrille.rand(times, value);
}
function keyPressed() {
+key ? times = +key : value = key === 'c' ? null : random(values);
p.html('mouse click: ' + (value === null ? 'clears ' + times + ' time(s)'
: 'fills ' + times + ' time(s) with ' + value));
}
rand()
is also exemplified in reflect, rotate, transpose, magnitude, ring, clear, fill, delete, insert, replace, visit_quadrille, width, height and size.
Syntax #
rand(times, value = null)
Parameters #
parameter | description |
---|---|
times | Number: number of cells to be (cleared) filled |
value | p5.Image | p5.Graphics | p5.Color | array | object | string | number | null : clear cells |