SHARE
TWEET

CSH2012 movingTurtle.py

calcpage Apr 15th, 2013 200 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. #movingTurtles.py       MrG     2013.0409
  3. import turtle
  4. import random
  5.  
  6. t=turtle.Turtle()
  7. t.color("red")
  8. t.pensize(5)
  9. t.speed(100)
  10.  
  11. wn=turtle.Screen()
  12. wn.bgcolor("grey")
  13.  
  14. print wn.window_width()
  15. print wn.window_height()
  16.  
  17. def isInScreen(wn,t):
  18.     xmin = -wn.window_width()/2
  19.     xmax = wn.window_width()/2
  20.     ymin = -wn.window_height()/2
  21.     ymax = wn.window_height()/2
  22.  
  23.     x = t.xcor()
  24.     y = t.ycor()
  25.  
  26.     if x<xmin or x>xmax:
  27.         return False
  28.     if y<ymin or y>ymax:
  29.         return False
  30.     return True
  31.  
  32. while isInScreen(wn,t):
  33.     t.fd(50)
  34.     isInScreen(wn,t)
  35.     coin=random.randrange(2)
  36.     if coin == 0:
  37.         t.left(90)
  38.     else:
  39.         t.right(90)
  40.    
  41. turtle.mainloop()
RAW Paste Data
Top