xxxxxxxxxx
25
function setup() {
createCanvas(400, 400);
let cols = 10;
let rows = 10;
let cellWidth = width / cols;
let cellHeight = height / rows;
for (let x = 0; x < cols; x++) {
for (let y = 0; y < rows; y++) {
let cellX = x * cellWidth;
let cellY = y * cellHeight;
if (mouseX > cellX && mouseX < cellX + cellWidth && mouseY > cellY && mouseY < cellY + cellHeight) {
fill(255, 0, 0); // Highlight the cell when the mouse is over it
} else {
fill(255);
}
rect(cellX, cellY, cellWidth, cellHeight);
}
}
}
function draw() {
background(220);
setup(); // Continuously redraw grid
}