Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

Find the derivative. f(x) 8 3 4 mix X O 4 x32 4 x32 3 -4x - x2

Answered: 1 week ago