title: Make circles (balls) bounce in window using Python Zelle Graphics
body: <p>I have a program in Python for making one ball bounce off of all 4 sides of a window, but now I need to make 10 balls using an array. I'm still very new to this and confused on how to implement this. I'll post what I have so far below:</p>
  
  <pre><code>#create 10 balls bouncing off all 4 sides of the window (400 x 500)
  #The ball must start moving after a click, then stop after a given amount of time
  #After a second click, the program ends
  
  #----Algorithm----#
  
  #create screen 400 x 500
  #create array of 10 circles in different starting points
  
  #wait for click anywhere on screen 
  #click anywhere on screen
  #all 10 balls move in different directions bouncing off all 4 walls
      #if ball hits left or right wall
              #dy=dy*-1
      #if ball hits top or bottom
              #dx=dx*-1 
  
  #ball moves for no more than 30 seconds
  #ball stops
  #wait for next click
  #program ends
  
  #----ProgramStarts----#
  
      from graphics import *
      import time, random 
  
  #create screen
  winWidth = 400;
  winHeight = 500;
  win = GraphWin('Ball Bounce', winWidth, winHeight);
  win.setBackground(color_rgb(255,255,255));
  win.setCoords(0,0,winWidth, winHeight);
  numBalls= 10;
  
  #create 10 balls
  def makeBall(center, radius, win):
  
      balls=[];
      radius=10;
  
      for i in range (0,numBalls):
          aBall=Circle(center, radius);
          aBall.setFill("red");
          aBall.draw(win);
          balls.append(aBall);
  
  
  #animate 10 balls bouncing off edges of window
  def bounceInWin(shape, dx, dy, xLow, xHigh, yLow, yHigh):
      clickPoint=win.getMouse();   
      delay = .005
      for x in range(900):
          shape.move(dx, dy)
          center = shape.getCenter()
          x = center.getX()
          y = center.getY()
          if x &lt; xLow:
              dx = -dx
          if x &gt; xHigh:
              dx = -dx
          if y &lt; yLow:
              dy = -dy
          if y &gt; yHigh:
              dy = -dy
          time.sleep(delay);
  
  
  #get a random Point
  def getRandomPoint(xLow, xHigh, yLow, yHigh):
      x = random.randrange(xLow, xHigh+1)
      y = random.randrange(yLow, yHigh+1)
      return Point(x, y)   
  
  #make ball bounce
  def bounceBall(dx, dy):    
      winWidth = 400
      winHeight = 500
      win = GraphWin('Ball Bounce', winWidth, winHeight);
      win.setCoords(0,0,winWidth, winHeight);
  
      radius = 10
      xLow = radius
      xHigh = winWidth - radius
      yLow = radius
      yHigh = winHeight - radius
  
      center = getRandomPoint(xLow, xHigh, yLow, yHigh)
      ball = makeBall(center, radius, win)
  
      bounceInWin(ball, dx, dy, xLow, xHigh, yLow, yHigh)
  
  bounceBall(3, 5);
  
  #wait for another click to end program
  win.getMouse(); #close doesn't work, tried putting in loop 
  win.close;
  </code></pre>