Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from visual import *
- squareSize = 20
- numChickens = 5
- fence = box(length = squareSize, height = squareSize)
- chickens = [sphere(color = color.yellow) for _ in xrange(numChickens)]
- times = []
- t = 0
- def within_fence(obj):
- return abs(obj.pos.x) < squareSize / 2 and abs(obj.pos.y) < squareSize / 2
- while chickens:
- t += 10
- for chicken in chickens:
- v_angle = vector(.15).rotate(random.uniform(0, 2 * math.pi))
- chicken.pos += v_angle
- if not within_fence(chicken):
- chickens.remove(chicken)
- times.append(t)
- print "chicken #%d hit the fence at time %ds" %(numChickens - len(chickens), t)
- rate(1000)
- print times
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement