Assigned Date: Monday, Oct. 8, 2007
Due Dates: Wednesday, Oct. 17, 2007
Due Time: 11:55pm
Last modified on November 09, 2007, at 09:58 AM (see updates)
Write a program to animate a ball (well, a circle) bouncing around in a window. (Similar to exercise 7.17 in book, p. 230)
The basic idea is to start the circle somewhere in the interior of the window. Use variables dx and dy (both initialized to 1) to control the movement of the circle. Use a large counted loop (say 10000 iterations), and each time through the loop move the circle using dx and dy. When the x-value of the center of the circle gets too large (it hits the edge), change dx to
-1. When it gets too small, change dx back to
1. Use a similar approach for dy.
Note: Your animation will probably run too fast. You can slow it down by using the
sleep() function from the
Initialize dx and dy to random values (between -1 and 1). When the x-value of the center of the circle gets too large (it hits the edge), negate dx. When it gets too small, negate it again. Use a similar approach for dy.
Make the ball bounce back when its circumference hits one of the edges.
When the mouse is clicked change the direction of the ball randomly.
Hint: Assuming your window is stored in variable
win.mouseY contain the x-y coordinates of the mouse every time it gets clicked. Note that accessing these variables does not pause the program.
ball.py as an attachment. It is fine to submit a partial solution for partial credit. However, you need to state in your email how far you went (e.g., I completed up to step 3).
Email subject should be "Assignment #3".
My email address is firstname.lastname@example.org.
The following policies are in effect for this assignment:
All identifiers should be meaningful.
Include your design (pseudocode) as comments in your program.
The following comments should appear in your program as the first lines in the file. Items in angle brackets are either to be removed or replaced with what is specified within the brackets: