'''animation2.py -- a second example of animation Jeff Ondich, 10/8/07 Depends on John Zelle's graphics library. ''' import time from graphics import * windowWidth = 600 windowHeight = 400 window = GraphWin('Animation 2', windowWidth, windowHeight) window.setBackground(color_rgb(255, 255, 255)) radius = 40 ball = Circle(Point(radius, windowHeight / 2), radius) ball.draw(window) print 'Type Ctrl-C in the terminal window to make the animation stop.' goingRight = True while True: if ball.getCenter().x > windowWidth - radius: goingRight = False elif ball.getCenter().x < radius: goingRight = True if goingRight: ball.move(2, 0) else: ball.move(-2, 0) time.sleep(0.01)