Question: Programming Language: Processing 3+ How to make the ball move, such that: The initial speed is based on the distance from the ball to the

Programming Language: Processing 3+

How to make the ball move, such that:

  • The initial speed is based on the distance from the ball to the mouse, where a small
  • distance between the mouse and ball gives a low speed and a large distance between the mouse and ball gives a high speed.
  • To implement this variety in the speed:
  • Determine the largest possible distance from the ball to the mouse, keeping in mind that a mouse click will only register if the mouse is on the canvas.
  • Choose a MAX_SPEED (try 10 pixels initially), and scale the distance from the ball to the mouse into a ball speed between 0 and MAX_SPEED.
  • Store the direction of motion for the ball as the angle from the ball to the location of the mouse when clicked.
  • Choose a SPEED_STEP (try 0.05 pixels initially), and reduce the ball speed by this amount each frame.
  • In each frame, convert the direction and speed to a change in x and y coordinates, and update the ball position to make the ball move.

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!