Write a GraphicsProgram that creates a ball (an instance of GOval) and makes it bounce around the screen. Ignore gravity and have a collision with the right or left wall reflect the x direction of the ball, and have a collision with the top or bottom wall change the y direction of the ball.

The figure below shows a ball moving through a bounce with the bottom wall.

Milestone 1: Create a Ball

It can be any size.

Milestone 2: Make it move

Loop forever and in the loop update the ball and pause. You can pause using the command:

If you don't pause the computer will animate faster that the human eye can see the movement!

There is also a method to move a GOval (or a GRect):

object.move(dx, dy);
dx is the number of pixels the object will move in the x direction.
dy is the number of pixels the object will move in the y direction.

Milestone 3: Bounce

Now, before you update the position of the ball, you should check if the ball has collided with the wall and if so you should update the direction it is moving.

Reflections should follow the rule the angle of incidence equals the angle of reflection. This turns out to be simple to implement. You simple flip the x direction if you hit a left or right wall and flip the y direction if you hit a bottom or top wall

How do you figure out the position of the ball? You can use the methods: