#Bouncing Balls #example released to the public domain #Spring 2009 # # from myro import * aWindow = GraphWin("Pong", 500,500) xPos = [50,10,100,10,250] yPos = [50, 25, 250,10,26] xDelta = [-2,-5,10,3,0] yDelta = [5,3,4,2,0] Balls = [] index = 0 while index < len(xPos): Ball = Circle( Point(xPos[index], yPos[index]), 10) Ball.draw(aWindow) Balls.append(Ball) index = index + 1 Balls[0].setFill( color_rgb(255,0,0) ) Balls[1].setFill( color_rgb(0,255,0) ) Balls[2].setFill( color_rgb(0,0,255) ) index = 3 while index < len(xPos): Balls[index].setFill( color_rgb(255,0,255) ) index = index + 1 print "Coloring leftover balls!" while timeRemaining(20): for index in range( len(xPos) ): if (0 > xPos[index]) or (500 < xPos[index]): xDelta[index] = - xDelta[index] if (0 > yPos[index]) or (500 < yPos[index]): yDelta[index] = - yDelta[index] xPos[index] = xPos[index] + xDelta[index] yPos[index] = yPos[index] + yDelta[index] Balls[index].move(xDelta[index], yDelta[index]) wait(0.01) #End of program.