Book
Module 5 - Section 1 - Graphics
Module 5 - Section 1 - Graphics
Completion requirements
View
After the completion of this module the students will be able to:
- describe how to draw shapes
- create code to animate a shape
- create code to bounce a shape inside a windows
- reproduce the code to animate and bounce two objects
- organize the code for multiple animation
5.1.4 - Multiple objects movement
Starting from the previous script, that we have created a white moving rectangle and a red frame, can you add code for the red frame to move and bounce to the edges of the screen?
As you can see the code is starting to be complicated so writing comments and keep the code tidy helps.
If you have an error in your script you can download the code from here
As you can see we managed to bounce two rectangles but we wrote everything twice (WET) which is against our programming principles: Don't repeat Yourself (DRY).