Wednesday, February 3, 2010

from visual import*
Container = cylinder(pos=(0,-11,0), axis=(0,22,0), radius=9, opacity=0.3, color=color.white)
Displacer = cylinder(pos=(0,10.999,0), axis=(0,.001,0), radius=Container.radius, opactiy=0.3, color=color.white)
Bottom = cylinder(pos=(0,-10.999,0,), axis=(0,.001,0), radius=Container.radius, opactiy=0.3, color=color.white)
ball1 = sphere(pos=( 0,0,0), radius=0.5, color=color.blue)
ball2 = sphere(pos=(0,0,0), radius=0.5, color=color.blue)
ball3 = sphere(pos=(0,0,0), radius=0.5, color=color.red)
ball4 = sphere(pos=(0,0,0), radius=0.5, color=color.red)
ball5 = sphere(pos=(0,0,0), radius=0.5, color=color.yellow)
ball6 = sphere(pos=(0,0,0), radius=0.5, color=color.yellow)
ball7 = sphere(pos=(0,0,0), radius=0.5, color=color.orange)
ball8 = sphere(pos=(0,0,0), radius=0.5, color=color.orange)
ball9 = sphere(pos=(0,0,0), radius=0.5, color=color.green)
ball10 = sphere(pos=(0,0,0), radius=0.5, color=color.green)
ball1.velocity = vector(50,60,70)
ball2.velocity = vector(-50,60,-70)
ball3.velocity = vector(60,70,50)
ball4.velocity = vector(-60,-70,50)
ball5.velocity = vector(50,60,70)
ball6.velocity = vector(-50,-60,70)
ball7.velocity = vector(50,-70,-60)
ball8.velocity = vector(60,-50,-70)
ball9.velocity = vector(70,50,60)
ball10.velocity = vector(70,-60,50)
deltat = .001
t = 0
scene.autoscale = False
while t < 1e5:
rate(10000)
if ball1.pos.x < ball1.radius - pow(abs((pow(Container.radius,2)-pow(ball1.pos.z,2))),.5):
ball1.velocity.x = - ball1.velocity.x
if ball1.pos.x > pow(abs((pow(Container.radius,2)-pow(ball1.pos.z,2))),.5) - ball1.radius:
ball1.velocity.x = - ball1.velocity.x
if ball1.pos.y < Bottom.pos.y + ball1.radius:
ball1.velocity.y = -ball1.velocity.y
if ball1.pos.y > Displacer.pos.y - ball1.radius:
ball1.velocity.y = -ball1.velocity.y
if ball1.pos.z < ball1.radius - pow(abs((pow(Container.radius,2)-pow(ball1.pos.x,2))),.5):
ball1.velocity.z = - ball1.velocity.z
if ball1.pos.z > pow(abs((pow(Container.radius,2)-pow(ball1.pos.x,2))),.5) - ball1.radius:
ball1.velocity.z = - ball1.velocity.z
if ball2.pos.x < ball2.radius - pow(abs((pow(Container.radius,2)-pow(ball2.pos.z,2))),.5):
ball2.velocity.x = - ball2.velocity.x
if ball2.pos.x > pow(abs((pow(Container.radius,2)-pow(ball2.pos.z,2))),.5) - ball2.radius:
ball2.velocity.x = - ball2.velocity.x
if ball2.pos.y < Bottom.pos.y + ball1.radius:
ball2.velocity.y = -ball2.velocity.y
if ball2.pos.y > Displacer.pos.y - ball2.radius:
ball2.velocity.y = -ball2.velocity.y
if ball2.pos.z < ball2.radius - pow(abs((pow(Container.radius,2)-pow(ball2.pos.x,2))),.5):
ball2.velocity.z = - ball2.velocity.z
if ball2.pos.z > pow(abs((pow(Container.radius,2)-pow(ball2.pos.x,2))),.5) - ball2.radius:
ball2.velocity.z = - ball2.velocity.z
if ball3.pos.x < ball3.radius - pow(abs((pow(Container.radius,2)-pow(ball3.pos.z,2))),.5):
ball3.velocity.x = - ball3.velocity.x
if ball3.pos.x > pow(abs((pow(Container.radius,2)-pow(ball3.pos.z,2))),.5) - ball3.radius:
ball3.velocity.x = - ball3.velocity.x
if ball3.pos.y < Bottom.pos.y + ball3.radius:
ball3.velocity.y = -ball3.velocity.y
if ball3.pos.y > Displacer.pos.y - ball3.radius:
ball3.velocity.y = -ball3.velocity.y
if ball3.pos.z < ball3.radius - pow(abs((pow(Container.radius,2)-pow(ball3.pos.x,2))),.5):
ball3.velocity.z = - ball3.velocity.z
if ball3.pos.z > pow(abs((pow(Container.radius,2)-pow(ball3.pos.x,2))),.5) - ball3.radius:
ball3.velocity.z = - ball3.velocity.z
if ball4.pos.x < ball4.radius - pow(abs((pow(Container.radius,2)-pow(ball4.pos.z,2))),.5):
ball4.velocity.x = - ball4.velocity.x
if ball4.pos.x > pow(abs((pow(Container.radius,2)-pow(ball4.pos.z,2))),.5) - ball4.radius:
ball4.velocity.x = - ball4.velocity.x
if ball4.pos.y < Bottom.pos.y + ball4.radius:
ball4.velocity.y = -ball4.velocity.y
if ball4.pos.y > Displacer.pos.y - ball4.radius:
ball4.velocity.y = -ball4.velocity.y
if ball4.pos.z < ball4.radius - pow(abs((pow(Container.radius,2)-pow(ball4.pos.x,2))),.5):
ball4.velocity.z = - ball4.velocity.z
if ball4.pos.z > pow(abs((pow(Container.radius,2)-pow(ball4.pos.x,2))),.5) - ball4.radius:
ball4.velocity.z = - ball4.velocity.z
if ball5.pos.x < ball5.radius - pow(abs((pow(Container.radius,2)-pow(ball5.pos.z,2))),.5):
ball5.velocity.x = - ball5.velocity.x
if ball5.pos.x > pow(abs((pow(Container.radius,2)-pow(ball5.pos.z,2))),.5) - ball5.radius:
ball5.velocity.x = - ball5.velocity.x
if ball5.pos.y < Bottom.pos.y + ball5.radius:
ball5.velocity.y = -ball5.velocity.y
if ball5.pos.y > Displacer.pos.y - ball5.radius:
ball5.velocity.y = -ball5.velocity.y
if ball5.pos.z < ball5.radius - pow(abs((pow(Container.radius,2)-pow(ball5.pos.x,2))),.5):
ball5.velocity.z = - ball5.velocity.z
if ball5.pos.z > pow(abs((pow(Container.radius,2)-pow(ball5.pos.x,2))),.5) - ball5.radius:
ball5.velocity.z = - ball5.velocity.z
if ball6.pos.x < ball6.radius - pow(abs((pow(Container.radius,2)-pow(ball6.pos.z,2))),.5):
ball6.velocity.x = - ball6.velocity.x
if ball6.pos.x > pow(abs((pow(Container.radius,2)-pow(ball6.pos.z,2))),.5) - ball6.radius:
ball6.velocity.x = - ball6.velocity.x
if ball6.pos.y < Bottom.pos.y + ball6.radius:
ball6.velocity.y = -ball6.velocity.y
if ball6.pos.y > Displacer.pos.y - ball6.radius:
ball6.velocity.y = -ball6.velocity.y
if ball6.pos.z < ball6.radius - pow(abs((pow(Container.radius,2)-pow(ball6.pos.x,2))),.5):
ball6.velocity.z = - ball6.velocity.z
if ball6.pos.z > pow(abs((pow(Container.radius,2)-pow(ball6.pos.x,2))),.5) - ball6.radius:
ball6.velocity.z = - ball6.velocity.z
if ball7.pos.x < ball7.radius - pow(abs((pow(Container.radius,2)-pow(ball7.pos.z,2))),.5):
ball7.velocity.x = - ball7.velocity.x
if ball7.pos.x > pow(abs((pow(Container.radius,2)-pow(ball7.pos.z,2))),.5) - ball7.radius:
ball7.velocity.x = - ball7.velocity.x
if ball7.pos.y < Bottom.pos.y + ball7.radius:
ball7.velocity.y = -ball7.velocity.y
if ball7.pos.y > Displacer.pos.y - ball7.radius:
ball7.velocity.y = -ball7.velocity.y
if ball7.pos.z < ball7.radius - pow(abs((pow(Container.radius,2)-pow(ball7.pos.x,2))),.5):
ball7.velocity.z = - ball7.velocity.z
if ball7.pos.z > pow(abs((pow(Container.radius,2)-pow(ball7.pos.x,2))),.5) - ball7.radius:
ball7.velocity.z = - ball7.velocity.z
if ball8.pos.x < ball8.radius - pow(abs((pow(Container.radius,2)-pow(ball8.pos.z,2))),.5):
ball8.velocity.x = - ball8.velocity.x
if ball8.pos.x > pow(abs((pow(Container.radius,2)-pow(ball8.pos.z,2))),.5) - ball8.radius:
ball8.velocity.x = - ball8.velocity.x
if ball8.pos.y < Bottom.pos.y + ball8.radius:
ball8.velocity.y = -ball8.velocity.y
if ball8.pos.y > Displacer.pos.y - ball8.radius:
ball8.velocity.y = -ball8.velocity.y
if ball8.pos.z < ball1.radius - pow(abs((pow(Container.radius,2)-pow(ball8.pos.x,2))),.5):
ball8.velocity.z = - ball8.velocity.z
if ball8.pos.z > pow(abs((pow(Container.radius,2)-pow(ball8.pos.x,2))),.5) - ball8.radius:
ball8.velocity.z = - ball8.velocity.z
if ball9.pos.x < ball9.radius - pow(abs((pow(Container.radius,2)-pow(ball9.pos.z,2))),.5):
ball9.velocity.x = - ball9.velocity.x
if ball9.pos.x > pow(abs((pow(Container.radius,2)-pow(ball9.pos.z,2))),.5) - ball9.radius:
ball9.velocity.x = - ball9.velocity.x
if ball9.pos.y < Bottom.pos.y + ball9.radius:
ball9.velocity.y = -ball9.velocity.y
if ball9.pos.y > Displacer.pos.y - ball9.radius:
ball9.velocity.y = -ball9.velocity.y
if ball9.pos.z < ball9.radius - pow(abs((pow(Container.radius,2)-pow(ball9.pos.x,2))),.5):
ball9.velocity.z = - ball9.velocity.z
if ball9.pos.z > pow(abs((pow(Container.radius,2)-pow(ball9.pos.x,2))),.5) - ball9.radius:
ball9.velocity.z = - ball9.velocity.z
if ball10.pos.x < ball10.radius - pow(abs((pow(Container.radius,2)-pow(ball10.pos.z,2))),.5):
ball10.velocity.x = - ball10.velocity.x
if ball10.pos.x > pow(abs((pow(Container.radius,2)-pow(ball10.pos.z,2))),.5) - ball10.radius:
ball10.velocity.x = - ball10.velocity.x
if ball10.pos.y < Bottom.pos.y + ball10.radius:
ball10.velocity.y = -ball10.velocity.y
if ball10.pos.y > Displacer.pos.y - ball10.radius:
ball10.velocity.y = -ball10.velocity.y
if ball10.pos.z < ball10.radius - pow(abs((pow(Container.radius,2)-pow(ball10.pos.x,2))),.5):
ball10.velocity.z = - ball10.velocity.z
if ball10.pos.z > pow(abs((pow(Container.radius,2)-pow(ball10.pos.x,2))),.5) - ball10.radius:
ball10.velocity.z = - ball10.velocity.z
ball1.pos = ball1.pos + ball1.velocity*deltat
ball2.pos = ball2.pos + ball2.velocity*deltat
ball3.pos = ball3.pos + ball3.velocity*deltat
ball4.pos = ball4.pos + ball4.velocity*deltat
ball5.pos = ball5.pos + ball5.velocity*deltat
ball6.pos = ball6.pos + ball6.velocity*deltat
ball7.pos = ball7.pos + ball7.velocity*deltat
ball8.pos = ball8.pos + ball8.velocity*deltat
ball9.pos = ball9.pos + ball9.velocity*deltat
ball10.pos = ball10.pos + ball10.velocity*deltat
t = t + deltat

No comments:

Post a Comment