import turtle import random import math screen = turtle.Screen() screen.bgcolor('yellow') # Set up boundry box size xMax=200 xMin=-200 yMax=200 yMin=-200 # Function to draw a box to bounce in def makeBoundary(right,left,top,bottom): # Finish Function... return # Function to setup ball def setupBall(ball,x,y,dX): # Set up starting values ball.penup() ball.shape('circle') # x, y, dX are object variables ball.x=x ball.y=y # We should make this random ball.dX=dX # Place ball at starting point ball.goto(ball.x,ball.y) # Function to animate ball one step def animate(ball): # use globals for boundries global xMax,xMin,yMax,yMin # Code here to bounce off the walls if ball.x > xMax or ball.x < xMin: # Reverse direction ball.dX = -ball.dX # Move to next position ball.x+=ball.dX ball.goto(ball.x,ball.y) # Call function to draw box makeBoundary(xMax,xMin,yMax,yMin) # create turtle, and initialize it ball1 = turtle.Turtle() setupBall(ball1,0,0,2) # Animate! while (True): animate(ball1);