Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started