xxxxxxxxxx
27
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
// define the number of columns
let numColumns = 20;
// calculate the width of each column
let columnWidth = width / numColumns;
// loop through the number of columns
for (let i = 0; i < numColumns; i++) {
// set the fill color based on hover status
fill(isHovered(i, columnWidth) ? 'red' : 'lavender');
// draw the rectangle for each column
rect(i * columnWidth, 0, columnWidth, height); // fill the height of the canvas
}
}
// check if the mouse is hovering over a specific column
function isHovered(index, columnWidth) {
let x = index * columnWidth;
return mouseX > x && mouseX < x + columnWidth && mouseY < height; // fill the height of the canvas
}