xxxxxxxxxx
let rows, cols;
let rectSize = 40;
function setup() {
createCanvas(400, 400);
rows = height / rectSize;
cols = width / rectSize;
noStroke();
drawPattern();
}
function drawPattern() {
background(220);
for (let i = 0; i < cols; i++) {
for (let j = 0; j < rows; j++) {
let x = i * rectSize;
let y = j * rectSize;
let r = random(255);
let g = random(255);
let b = random(255);
fill(r, g, b);
rect(x, y, rectSize, rectSize);
}
}
}
function mouseClicked() {
if (rectSize === 40) {
rectSize = 20;
} else {
rectSize = 40;
}
drawPattern();
}