if / else help required
in
Programming Questions
•
9 months ago
I am currently trying to create a script that allows the squares to enlarge as you roll over them with the mouse. What I have created is clunky (I'm referring to the 'mouse location' section), and doesn't appear to really work - I know that I am going wrong somewhere, and going a labored way around it - does anyone have any pointers for me? I'd be very grateful indeed.
The code:
//VARIABLES
float xcoord;
float ycoord;
float division;
float xdivider;
float ydivider;
color start=color(0,0,0);
color finish;
float amt = 0.0;
//SETUP
void setup() {
size(600,600);
background(start);
finish = color(random(255),random(255),random(255));
division=6;
xdivider=width/division;
ydivider=height/division;
smooth();
strokeWeight(1.5);
rectMode(CENTER);
}
//DRAWING
void draw() {
amt+=.01;
if (amt >= 1) {
amt = 0.0;
start = finish;
finish = color(random(255),random(255),random(255));
}
background (51);
fill(255, 204);
for (xcoord=xdivider; xcoord<=width-xdivider; xcoord=xcoord+xdivider)
{
for (ycoord=ydivider; ycoord<=height-ydivider; ycoord=ycoord+ydivider)
{
//RECTANGLE
pushMatrix();
translate(xcoord, ycoord);
stroke(255);
fill (lerpColor(start,finish,amt));
rect( 0, 0, 50, 50 );
popMatrix();
//MOUSE LOCATION
if (mouseX < 100 && mouseY < 100) {
rect(100,100,100,100);
} else if (mouseX > 200 && mouseY < 100) {
rect(200,100,100,100);
} else if (mouseX < 300 && mouseY > 100) {
rect(300,100,100,100);
} else if (mouseX > 400 && mouseY > 100) {
rect(400,100,100,100);
} else if (mouseX > 100 && mouseY < 200) {
rect(100,200,100,100);
}
}
}
}
Many thanks in advance!!
1