title: How to make ball touch edge of window in Python?
body: <p>I have this code for a ball bouncing on around the window. And, it doesn't touch 100% the edge of the window, but my teacher would like it to. How do you modify this? The ball also appears to be moving really fast so it doesn't even resemble a circle. Does anyone have any idea why this happening? Thank you.</p>
  
  <pre><code>from graphics import * #import graphics file
  import time #import time module
  from random import randrange
  def main():
      win = GraphWin('Bouncing Ball', 500, 500) #create a window to draw upon
      x=randrange(50,450)
      y=randrange(50,450)
      a=1
      b=1
  
      circ1 = Circle(Point(x,y),10)
      circ1.setFill("green")
      circ1.draw(win)
  
  
      for i in range(2000): #"i" establishes the amount of time the stuff below runs for
          circ1.move(a,b)
          center = circ1.getCenter()
          x = center.getX()
          y = center.getY()
          if 500-(x+25)&lt;1:
              z=randrange(1,4)
              if (a&lt;0):
                  a=-z
              else:
                  a=z
                  a=-a
              #to not alter speed use this as code instead:
              # a=-a
          elif x-25&lt;1:
              z=randrange(1,4)
              if (a&lt;0):
                  a=z
              else:
                  a=-z
          if 500-(y+25)&lt;1:
              z=randrange(1,4)
              if (b&lt;0):
                  b=-z
              else:
                  b=z
              b=-b
          elif y-25&lt;1:
              b=-b
          time.sleep(.05)
  
  main()
  </code></pre>