diff --git a/cse16260_ex4_q1.py b/cse16260_ex4_q1.py new file mode 100644 index 0000000000000000000000000000000000000000..34226ee3e6994d1c02d682707fd6731ba07aef79 --- /dev/null +++ b/cse16260_ex4_q1.py @@ -0,0 +1,36 @@ +from vpython import * +#GlowScript 2.7 VPython +ball = sphere(pos=vector(-5,0,0), radius=0.5, + color=color.cyan, make_trail=True) +wallR = 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) +wallU = box(pos=vector(0,6,0), size=vector(12,0.2,12), color=color.green) +wallD = box(pos=vector(0,-6,0), size=vector(12,0.2,12), color=color.green) +wallB = box(pos=vector(0,0,-6), size=vector(12,12,0.2), color=color.green) +#wallF = box(pos=vector(0,0,6), size=vector(12,12,0.2), color=color.green) + + +ball.velocity = vector(25,5,10) +deltat = 0.005 +t = 0 +ev=scene.waitfor('keydown') + +ball.pos = ball.pos + ball.velocity*deltat +vscale = 0.1 +varr = arrow(pos=ball.pos, axis=vscale*ball.velocity, color=color.yellow) +#scene.autoscale = False +while t < 3: + rate(100) + if ball.pos.x > wallR.pos.x or ball.pos.x<wallL.pos.x: + ball.velocity.x = -ball.velocity.x + if ball.pos.y > wallU.pos.y or ball.pos.y<wallD.pos.y: + ball.velocity.y = -ball.velocity.y + if ball.pos.z<wallB.pos.z: + ball.velocity.z = -ball.velocity.z + ball.pos = ball.pos + ball.velocity*deltat + varr.axis=vscale*ball.velocity + varr.pos=ball.pos + t = t + deltat + + +