from visual import * scene.width=800 scene.hieght=50 scene.autoscale=0 ball = sphere(pos=(-5,0,0), radius=2, color=color.green) ball2 = sphere(pos=(5,0,0), radius=1, color=color.yellow) m1 = 14.0 m2 = 10.0 dt = 0.1 bv =3.0 b2v=-2.0 ball2.velocity = vector (-2.0,0.0,0.0) ball.velocity = vector(3.0,0.0,0.0) while (1==1): print "in loop 1" rate(100) ball2.pos = ball2.pos + ball2.velocity*dt ball.pos = ball.pos + ball.velocity*dt if ((ball2.x )-(ball.x)<3): ball.velocity.x = (((m1-m2)*bv)+((2*m2)*b2v))/(m1+m2) ball2.velocity.x = (((2*m1)*bv)+((m2-m1)*b2v))/(m1+m2) b2v=ball2.velocity.x bv=ball.velocity.x if ball.x<-7.75: ball.velocity.x = -ball.velocity.x if ball2.x > 9.25: ball2.velocity.x = -ball2.velocity.x print ball.velocity.x,ball2.velocity.x print ball.pos.x,ball2.pos.x