Advertisement
lezed1

Random Chicken V2

Jun 11th, 2014
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. from visual import *
  2.  
  3. squareSize = 20
  4. numChickens = 5
  5.  
  6. fence = box(length = squareSize, height = squareSize)
  7. chickens = [sphere(color = color.yellow) for _ in xrange(numChickens)]
  8. times = []
  9.  
  10. t = 0
  11.  
  12. def within_fence(obj):
  13.   return abs(obj.pos.x) < squareSize / 2 and abs(obj.pos.y) < squareSize / 2
  14.  
  15. while chickens:
  16.   t += 10
  17.   for chicken in chickens:
  18.     v_angle = vector(.15).rotate(random.uniform(0, 2 * math.pi))
  19.     chicken.pos += v_angle
  20.     if not within_fence(chicken):
  21.       chickens.remove(chicken)
  22.       times.append(t)
  23.       print "chicken #%d hit the fence at time %ds" %(numChickens - len(chickens), t)
  24.  
  25.   rate(1000)
  26.  
  27. print times
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement