Tuesday, March 16, 2010

Visual Python

from visual import *
cylinder(pos=(0,0,0), radius=2, height=40, length=10, color=color.cyan, opacity=0.1)
cylinderA=cylinder(pos=(9,0,0), radius=2, heigth=40, length=.02, color=color.green)
cylinderA.velocity=vector(-5,0,0)
ball=sphere(pos=(1,0,0), radius=.1, color=color.red)
ball.velocity=vector(25,10,15)
ball1=sphere(pos=(2,0,0), radius=.1, color=color.orange)
ball1.velocity=vector(50,10,15)
ball2=sphere(pos=(3,0,0), radius=.1, color=color.yellow)
ball2.velocity=vector(10,30,40)
ball3=sphere(pos=(4,0,0), radius=.1, color=color.green)
ball3.velocity=vector(5,10,15)
ball4=sphere(pos=(5,0,0), radius=.1, color=color.blue)
ball4.velocity=vector(13,32,50)
ball5=sphere(pos=(6,0,0), radius=.1, color=color.red)
ball5.velocity=vector(1,5,4)
ball6=sphere(pos=(7,0,0), radius=.1, color=color.orange)
ball6.velocity=vector(22,15,34)
deltat=.003
t=0
ball.pos=ball.pos+ball.velocity*deltat
while t<1000:
rate(50)
if ball.pos.x>cylinderA.pos.x:
ball.velocity.x=-ball.velocity.x
if ball.pos.x<0:
ball.velocity.x=-ball.velocity.x
if (ball.pos.y**2)+(ball.pos.z**2)>(2**2):
ball.velocity.y=-ball.velocity.y
ball.velocity.z=-ball.velocity.z
ball.pos=ball.pos+ball.velocity*deltat
t=t+deltat
if ball1.pos.x>cylinderA.pos.x:
ball1.velocity.x=-ball1.velocity.x
if ball1.pos.x<0:
ball1.velocity.x=-ball1.velocity.x
if (ball1.pos.y**2)+(ball1.pos.z**2)>(2**2):
ball1.velocity.y=-ball1.velocity.y
ball1.velocity.z=-ball1.velocity.z
ball1.pos=ball1.pos+ball1.velocity*deltat
t=t+deltat
if ball2.pos.x>cylinderA.pos.x:
ball2.velocity.x=-ball2.velocity.x
if ball2.pos.x<0:
ball2.velocity.x=-ball2.velocity.x
if (ball2.pos.y**2)+(ball2.pos.z**2)>(2**2):
ball2.velocity.y=-ball2.velocity.y
ball2.velocity.z=-ball2.velocity.z
ball2.pos=ball2.pos+ball2.velocity*deltat
t=t+deltat
if ball3.pos.x>cylinderA.pos.x:
ball3.velocity.x=-ball3.velocity.x
if ball3.pos.x<0:
ball3.velocity.x=-ball3.velocity.x
if (ball3.pos.y**2)+(ball3.pos.z**2)>(2**2):
ball3.velocity.y=-ball3.velocity.y
ball3.velocity.z=-ball3.velocity.z
ball3.pos=ball3.pos+ball3.velocity*deltat
t=t+deltat
if ball4.pos.x>cylinderA.pos.x:
ball4.velocity.x=-ball4.velocity.x
if ball4.pos.x<0:
ball4.velocity.x=-ball4.velocity.x
if (ball4.pos.y**2)+(ball4.pos.z**2)>(2**2):
ball4.velocity.y=-ball4.velocity.y
ball4.velocity.z=-ball4.velocity.z
ball4.pos=ball4.pos+ball4.velocity*deltat
t=t+deltat
if ball5.pos.x>cylinderA.pos.x:
ball5.velocity.x=-ball5.velocity.x
if ball5.pos.x<0:
ball5.velocity.x=-ball5.velocity.x
if (ball5.pos.y**2)+(ball5.pos.z**2)>(2**2):
ball5.velocity.y=-ball5.velocity.y
ball5.velocity.z=-ball5.velocity.z
ball5.pos=ball5.pos+ball5.velocity*deltat
t=t+deltat
if ball6.pos.x>cylinderA.pos.x:
ball6.velocity.x=-ball6.velocity.x
if ball6.pos.x<0:
ball6.velocity.x=-ball6.velocity.x
if (ball6.pos.y**2)+(ball6.pos.z**2)>(2**2):
ball6.velocity.y=-ball6.velocity.y
ball6.velocity.z=-ball6.velocity.z
ball6.pos=ball6.pos+ball6.velocity*deltat
t=t+deltat

No comments:

Post a Comment