sevenoreo.blogg.se

Pmouse x pmouse y
Pmouse x pmouse y







pmouse x pmouse y

tell me if I haven't satisfied any of the above possibilities if the cursor is inside the bottom square and the color of the top If the cursor is inside the top square and the color of the bottom if the cursor is inside the top square and the color of the bottom The mouseClicked function is called after a mouse button is pressed In this program, clicking inside one of the squares will make the other square change color. mouseClicked() is a separate function written in its own block after draw(). Richardson Example 4.1: More things you can do with the mouseīelow is another example program that uses mouseClicked(). The circle follows the mouse around and it changes color, just like we specified.Į. It doesn't move but it does change color depending on where the cursor is. So let's see what it looks like when it's running. Even if both of these turned out not to be true, we're going to draw this rectangle every time, and the ellipse is going to follow the mouse around. When you write if statements that aren't nested, that are separate from each other, you have to make sure that the test couldn't be satisfied by both of them at the same time because that will give you strange results that you're not expecting. Same down here, but we're just giving it different places to look for and then different fill color in case this is true. So this logical and here means that both of these have to be satisfied in order to execute this command. The first one says that, if the cursor is greater than 100 and x and less than 100 and y, to make the fill this color. And then we have two if statements, one after another. Here in the draw block, we're setting a default fill color. And we're telling it what size to make the display window. First thing we do is tell it to make the background the color that we set up here. Up here, we're setting a color variable with these values. Here's what this program does line by line. Both the circle and square change color depending on the cursor's position. The circle follows the cursor around the display window. This program draws a square and circle to the screen. You can take advantage of this by telling your program to do various things depending on where the cursor is.

pmouse x pmouse y

It also stores the most recent previous position of the cursor in the variables pmouseX and pmouseY. It stores that position inside the variables mouseX and mouseY. Processing stores the position of the cursor as long as the cursor is inside the display window. Syntax introduced: mouseX mouseY pmouseX pmouseY mouseClicked() keyPressed boolean elseĪnother fun thing to do is write programs that involve interactivity via the keyboard and the mouse.









Pmouse x pmouse y