# File: exp7.py # # Simple test of graphics module from textbook # See documentation in: # # http://mcsp.wartburg.edu/zelle/python/graphics/graphics/graphics.html # # This time the square wraps around to the left side # when it marches off the right side. # Note the use of % throughout. from graphics import * import time def drawBox(x, y, color): box = Rectangle(Point(x,y), Point(x+20,y+20)) box.setFill(color) box.setWidth(0) box.draw(win) # make a window for drawing stuff win = GraphWin("Hello", 500, 500) # inital point x = 0 y = 240 # draw first box drawBox(x,y,"orange") # iterate a lot for i in range(40): # erase old box drawBox(x,y,"white") # compute new x position x = (x + 20) % 500 # draw new box drawBox(x,y,"orange") time.sleep(.2) # end of for i # wait before closing window time.sleep(60) # make the window go away win.close()