As mentioned at the end of last section, we want to make the ball bounce within the canvas "walls". In order to do so, it is important to remember that the position of the ball is that of its centre, and that the part that hits a wall is its edge, located a distance equal to the radius away from the centre.
With the ball moving as fast as it does, it might be a bit difficult to
see what is going on. If you are curious, I suggest that you change
BALL_dx
and BALL_dy
in the html editor to larger
values and change the animation frame rate, from 1000 / 60
(i.e. 60
frames per 1000 milliseconds, or 60 frames per second) to something like
10 or even only 1 frame per second.
Next, I will fix the bug, making the ball bounce "correctly".
Keep your personal notes here. These notes are stored by your browser on your own computer, and will be available from any page on this site. You can choose to use html syntax for formatting.