D – 9: Using Python Turtle module to draw advanced animated figures
Assignment 9 – A. Bouncing Balls
Modify the BouncingBall program discussed in class to bounce two balls inside the rectangle. When the balls hit the walls, they bounce off the wall and continue as shown in the class example. When balls hit each other, they should reverse their direction away from each other in their original direction.
Assignment 9 – B. Analog Clock
Create an analog clock. The following code prints a simple digit clock.
In addition, we can use the attributes tm_hour, tm_min, and tm_sec to access values for the hour, min, and sec, respectively:
localtime = time.localtime() hour = localtime.tm_hour min = localtime.tm_min sec = localtime.tm_sec
To simulate an analog clock, first, draw a circle, and draw three lines to represent the hour, minute, and second hands. Use the hour, min, and sec values to calculate the angles and draw the hour, minute, and second hands of the analog clock. Sleep for one second, and update the hour, minute, and second hands, repeatedly.