Make an 100x100 size in processing 4, fill it with squares with size 10, in a grid of…
- User
Make an 100x100 size in processing 4, fill it with squares with size 10, in a grid of 10x10. then make it so if your mouse hovers over 1 square it will highlight THAT specific square
- Assistant
To create a 100x100 size grid in Processing 4, filled with 10x10 squares, and highlight a square when the mouse hovers over it, you can use the following code:
int gridSize = 10; int squareSize = 10; int highlightX = -1; int highlightY = -1; void setup() { size(100, 100); noLoop(); } void draw() { background(255); // Draw the grid of squares for (int x = 0; x < gridSize; x++) { for (int y = 0; y < gridSize; y++) { // Highlight the square if the mouse is over it if(x == highlightX && y == highlightY) { fill(200, 200, 0); // yellowish color for highlight } else { fill(240); // light gray for regular squares } rect(x * squareSize, y * squareSize, squareSize, squareSize); } } } void mouseMoved() { // Calculate the grid position of the mouse highlightX = mouseX / squareSize; highlightY = mouseY / squareSize; // Only proceed if the mouse is within the grid if (highlightX >= 0 && highlightX < gridSize && highlightY >= 0 && highlightY < gridSize) { redraw(); } else { // Reset highlights if mouse is outside the grid highlightX = -1; highlightY = -1; redraw(); } } - User
Explain how this code works:
if (highlightX >= 0 && highlightX < 10 && highlightY >= 0 && highlightY < 10) { redraw(); } else { highlightX = -1; highlightY = -1; redraw(); }
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.