CSE 1710.03A Programming for Digital Media

Lab 12

Due date: Dec 7, 2009 at 20:00

An animation of a bouncing rectangle

A simple way to create the animation of an object bouncing around on the screen is to advance the rectangle one step at a time and then refresh the screen. For this you need to do the following: First, create an empty image. Then select a random position (x,y), and draw a filled rectangle at that position. Select a random diagonal direction (dx,dy) and then show the image.
Then loop over the following steps: First, erase the (old) rectangle by drawing a white rectangle over it. Then add the (dx,dy) direction to the current position and draw the (new) rectangle there. Then redraw the image in the current window.
The size of the image must be 400 x 300 pixels. The rectangle must be filled in red and must be 20 x 20 pixels. The function to generate the animation must be called bounce() and must execute two thousand iterations/steps and stop after that.

Here are a couple of hints:

What to Turn in

The file containing both functions defined above must be named lab12.py.

As mentioned previously, you have to add comments with your own identification (name, student ID, date). Remember to save the file after you modify it!

How to submit

As in the labs, you hand in this lab the submit command on the Linux systems that are behind the PRISM lab infrastructure. For details on how to submit, please refer to lab02. However, this time please submit to lab12, i.e. issue the command

submit 1710 lab12 lab12.py

Note: You must do all the above steps correctly for receiving full credit for this labtest.