xxxxxxxxxx
27
let cols = 10;
let rows = 10;
let cellWidth;
let cellHeight;
function setup() {
createCanvas(400, 400);
cellWidth = width / cols;
cellHeight = height / rows;
}
function draw() {
background(255); // clear the background
for (let i = 0; i < cols; i++) {
for (let j = 0; j < rows; j++) {
let x = i * cellWidth; // x position of the cell
let y = j * cellHeight; // y position of the cell
if (mouseX > x && mouseX < x + cellWidth && mouseY > y && mouseY < y + cellHeight) {
fill(255, 0, 0); // change color to red on hover
} else {
fill("lavender"); // default color
}
rect(x, y, cellWidth, cellHeight); // draw the cell
}
}
}