We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So (mouseX > 0 && mouseX < width /2 && mouseY > 0 && mouseY < height/2) makes it so it displays whenever the mouse is in the top left corner of the screen, how would I make it to do the same thing except for the bottom left corner, top right corner and lower right corner of the screen if the size is 600 by 600?
Answers
http://studio.ProcessingTogether.com/sp/pad/export/ro.9hc1FSKJk66wK
this is wrong:::::::::
I misunderstood you...
So the
!
means notThis is what i am trying to do except make something for each portion of the screen.
Do you understand - at all - what the code on line 11 says?
If you did, you should be able to do this yourself.
Let's break it down.
This is a conditional statement. If the conditions are all met, then the code that is between the {} that follow it will be executed.
Cooking is a good analogy. Let's say you're making a sandwich.
If you have some cheese, you should put cheese on your sandwich.
Whoa, did you grok that? A conditional statement in English! Here's what it might look like in code:
But wait, what if the cheese is moldy?!? You need to add an additional conditional! If you have cheese AND the cheese is mold-free....
Ok. Now let's look at the line of code again.
Hopefully now you can see this as the ANDing of several conditionals.
Now what does the first conditional check? It's doing a comparison between the variable mouseX and the value 0. If you were to read this out loud, you might read it as "mouse X is greater than zero", because the > symbol is a greater-than sign.
This first conditional makes sure that the mouses X position is greater than zero.
What does the second conditional say? Like the first, it is doing a comparison with mouseX, so you know it is checking if the mouse's X position meets some criteria.
The criteria is that mouseX is less than width / 2.
What is width / 2? Half the width of the sketch!
What does it mean for mouseX to be less than half the sketch's width?
It means that the mouse is on the LEFT HALF of the sketch!
... You should be able to work the rest out from here on your own.
TfGuy44 explained it really well
I mean
mouseX
, andmouseY
is the mouse position (x goes to the right, y to the bottom).just try it here:
now, we want to check the position of the mouse against an area on the screen, let's say a rectangle:
If the mouse is inside the rectangle it means that:
the mouseX is bigger than > the left side of the rect (or the upper left corner if you like)
the mouseY is bigger than > the upper side
now we took care of the upper left corner if you like.
but we also have to check that the mouse is really inside the rectangle and not somewhere far off to the right or below the rectangle!
Therefore we also check if :
mouseX is smaller than < the right side of the rectangle (lower right corner) and
mouseY is smaller than < the lower side of the rectangle
That's it. In an if-clause we connect those 4 criteria with AND &&.
Now, one thing that may confuse you is that we use the absolute screen position here 4 times: so upper left corner is x1,y1 and lower right corner is x2,y2 but the command
rect()
if you draw the rectangle uses only one absolute screen position x1,y1 and the two next parameters are width and height of the rectangle (w,h).So when you draw the rectangle you say x1,y1,w,h and when you check the mouse against it you check it against x1,y1 and x2,y2 (but it is simple to calculate: x2 is x1+w and y2 is y1+h).
check it out:
you see, we basically add
110 and 60 to get x2 and
200 and 70 to get y2
Best, Chrisir ;-)
here you can see the x1,y1 and x2,y2 on the rectangle: