Based on an example by Mehran Sahami
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.
It can be any size.
Loop forever and in the loop update the ball and pause. You can pause using the command:
There is also a method to move a GOval (or a GRect):
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 simply 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: