xxxxxxxxxx
30
let cellSize;
let colorMap = new Map();
function setup() {
createCanvas(windowWidth, windowHeight);
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function draw() {
background(255);
strokeWeight(1);
cellSize = min(width / 50, height / 50);
for (let x = 0; x < width; x += cellSize) {
for (let y = 0; y < height; y += cellSize) {
let key = x + "," + y; // Create a unique key for each cell
if (mouseX > x && mouseX < x + cellSize && mouseY > y && mouseY < y + cellSize) {
colorMap.set(key, color(200,0,100)); // Change color on hover
}
fill(colorMap.get(key) || 255); // Use stored color or default white
square(x, y, cellSize);
}
}
}