title: Python Turtle checking for bounds (not working)
body: <p>I have a program where there is a box of BOUNDING_UNITS. Now ,I have to draw triangles inside the box in a random fashion. (random orientation). 
  However, for some reason, the triangles are going outside the box. </p>
  
  <p>This is what its looking like :
  <a href="https://i.stack.imgur.com/C6Sga.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C6Sga.png" alt="enter image description here"></a></p>
  
  <p>The correct solution would be to have all the three points of the triangle inside the square box. </p>
  
  <p>This are  functions : </p>
  
  <pre><code>def doTriangles(num):
      if num&lt;=0:
          return
      isColliding =True
  
      while isColliding:
  
          goingX=random.randint(-1*BOUNDING_BOX(),BOUNDING_BOX())
          goingY=random.randint(-1*BOUNDING_BOX(),BOUNDING_BOX())
          newDir = random.randint(1,60)
          newLen=200
  
  
          isColliding =checkForCollision(newLen,goingX,goingY,newDir)
  
          if isColliding == False:
              up()
              goto(goingX,goingY)
              setheading(newDir)
              down()
              doOneTriangle(newLen)
  
  
  
  
  
      doTriangles(num-1)
  
      print("hold me")
  
  
  
  
  
  
  
  
  def checkForCollision(len,positionX,positionY,heading):
  
      up()
  
      x=int(xcor())
      y=int(ycor())
      pprint.pprint(locals())
  
      if x&gt;=BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      elif x&lt;=-1*BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      elif y&gt;=BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      elif y&lt;=-1*BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
  
  
      up()
      right(90)
      fd(len/2)
  
  
      x=int(xcor())
      y=int(ycor())
      pprint.pprint(locals())
  
      if x&gt;=BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      elif x&lt;=-1*BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      elif y&gt;=BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      elif y&lt;=-1*BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
  
  
  
  
  
  
      left(120)
  
      fd(len)
  
  
      x=int(xcor())
      y=int(ycor())
      pprint.pprint(locals())
  
      if x&gt;=BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      elif x&lt;=-1*BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      elif y&gt;=BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      elif y&lt;=-1*BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
  
  
  
  
  
  
      left(120)
      fd(len)
  
  
      x=int(xcor())
      y=int(ycor())
      pprint.pprint(locals())
  
      if x&gt;=BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      elif x&lt;=-1*BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      elif y&gt;=BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      elif y&lt;=-1*BOUNDING_BOX():
          goto(positionX,positionY)
          setheading(heading)
          return True
      else:
          goto(positionX,positionY)
          setheading(heading)
          print("I RETURNED FALSE  ")
          return False
  
  
  
  
  
  def doOneTriangle(len):
  
  
  
      up()
      right(90)
      fd(len/2)
      down()
      left(120)
  
      #begin_fill()
      fd(len)
      left(120)
      fd(len)
      left(120)
      fd(len)
      left(120)
      fd(len)
      right(30)
  
     # end_fill()
  </code></pre>
  
  <p>What am I doing wrong ?</p>