# written by Lenore Horner, 2009 from visual import * Ndrops = 10 toggle = 0 # 0 makes all drops the same mass; 1 makes all drops the same density power = 2 constant = .5 dropheight = 4 dt = 0.01 floor = box(length=8, height=0.5, width=8, pos=(0,-dropheight,0), color=color.blue) Drops = [] for i in range(Ndrops): # create drops of various sizes at rest at common height Drops = Drops + [sphere(radius = random.uniform(0.1,1), color=color.red)] Drops[i].velocity = vector(0,0,0) Drops[i].acceleration = vector(0,9.8,0) Drops[i].pos = vector(random.uniform(-3.5,3.5),dropheight,random.uniform(-3.5,3.5)) while 1: rate(100) for i in range(Ndrops): # let all the drops fall Drops[i].pos = Drops[i].pos + Drops[i].velocity*dt if Drops[i].y < -dropheight + Drops[i].radius + 0.5: Drops[i].velocity.y = -Drops[i].velocity.y else: Drops[i].velocity.y = Drops[i].velocity.y + Drops[i].acceleration.y*dt volume = Drops[i].radius**3 accel = sign(Drops[i].velocity.y) * constant*Drops[i].radius**2*Drops[i].velocity.y**power / (volume)**toggle Drops[i].acceleration.y = -9.8 - accel