conditional statements / mouse over activation problem
in
Programming Questions
•
2 months ago
Learning the ropes and taking a Processing course online. In this sketch I'm trying to make the mouse cursor make the rectangle flash when it hovers over it. I'm not quite hitting the mark yet as the rectangle activates when the cursor is not exactly over it. I'm pretty sure the error is in the conditional statement defining the mouse coordinates. I sourced the code from an example provided on the Processing website. I just can't get my head around the logic quite yet.
int recty;
int rectsX, rectsY;
void setup()
{
size(500,500);
rectx = 250;
recty = 250;
rectsX = 200;
rectsY = 80;
}
void draw() {
background(125);
noStroke();
if (mouseX > rectx-rectsX && mouseX < recty+rectsY &&
mouseY > rectx-rectsX && mouseY < recty+rectsY) {
fill(random(255),random(255),random(255));
}
else {
fill(255);
}
rectMode(CENTER);
rect(rectx,recty,rectsX,rectsY);
}
Here's my code:
_______________________________
int rectx;
_______________________________
int recty;
int rectsX, rectsY;
void setup()
{
size(500,500);
rectx = 250;
recty = 250;
rectsX = 200;
rectsY = 80;
}
void draw() {
background(125);
noStroke();
if (mouseX > rectx-rectsX && mouseX < recty+rectsY &&
mouseY > rectx-rectsX && mouseY < recty+rectsY) {
fill(random(255),random(255),random(255));
}
else {
fill(255);
}
rectMode(CENTER);
rect(rectx,recty,rectsX,rectsY);
}
1