diff --git a/cb.en.u4cse16249_wallAndBall.py b/cb.en.u4cse16249_wallAndBall.py new file mode 100644 index 0000000000000000000000000000000000000000..41bbeda6403f5664eba3fe3ba9c11d728631df7d --- /dev/null +++ b/cb.en.u4cse16249_wallAndBall.py @@ -0,0 +1,39 @@ +from vpython import * +#GlowScript 2.7 VPython +ball = sphere(pos=vector(-5,0,0),radius=1,color=color.red,make_trail=True) +wall = box(pos=vector(6,0,0),size=vector(0.2,12,12),color=color.green) +wallL= box(pos=vector(-6,0,0),size=vector(0.2,12,12),color=color.green) +wall1 =box(pos=vector(0,6,0),size=vector(-12,0,12),color=color.green) +wall2 =box(pos=vector(0,-6,0),size=vector(-12,0,12),color=color.green) +vscale=0.1 +ball.velocity=vector(25,3,0) +varr=arrow(pos=ball.pos,axis=vscale*ball.velocity,color=color.yellow) +delta=0.005 +t=0 +while(t>=0): + rate(100) + if(ball.pos.y>wall1.pos.y): + ball.color=color.white + ball.velocity.x=-ball.velocity.x + ball.velocity.y=-ball.velocity.y + varr.axis=ball.velocity*vscale + ball.pos=ball.pos+(ball.velocity*(delta)) + varr.pos=varr.pos+(ball.velocity*(delta)) + t=t+delta + if(ball.pos.x==wall.pos.x): + ball.velocity.x=-ball.velocity.x + varr.axis=ball.velocity*vscale + ball.pos=ball.pos+(ball.velocity*(delta)) + varr.pos=varr.pos+(ball.velocity*(delta)) + t=t+delta + else if(ball.pos.x==wallL.pos.x): + ball.velocity.x=-ball.velocity.x + varr.axis=ball.velocity*vscale + ball.pos=ball.pos+(ball.velocity*(delta)) + varr.pos=varr.pos+(ball.velocity*(delta)) + t=t+delta + else: + ball.pos=ball.pos+ball.velocity*delta + varr.pos=varr.pos+(ball.velocity*(delta)) + t=t+delta +