Question: PROCESSING CODE Can anyone help me how to make a condition that happen when another condition true first then false later. For example, create a

PROCESSING CODE

Can anyone help me how to make a condition that happen when another condition true first then false later.

For example, create a circle object. When we press on the object with mouse then we release mouse in another location outside the object, the object will move toward mouse. I tried some thing like this but it not working. Can someone please fix my code. Thank you

int ballX=50)); //x coordinate of ball

int ballY=,50)); //y coordinate of ball

final int SIZE = 30; //size of ball

circle(ballX,ballY,SIZE); // draw the ball

float dist = sqrt(sq(mouseX-ballX) + sq(mouseY-ballY)); // distance between mouse and ball center

if (mousePress && dist < SIZE/2){ /*if we press the mouse and the distance between mouse ball center is less than ball radius (which mean we press on the ball)*/

if(!mousePress){ //Then if we release the mouse

ballX= ballX+ dist/10;

ballY = ballY + dist/10; //The ball is moving toward the mouse

}

}

Some how this code doesn't work. Can some one please spot my mistake and help me fix my code? Please don't make it too complicated, only IF ELSE (beginner processing). Thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!