Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from visual import *
- from visual.graph import *
- scene.width=800
- scene.height=800
- scene.range=(16,16,16)
- scene.autoscale = 0
- scene.center=(0,12,0)
- scene.background=color.white
- ball = sphere(pos=(0,20,0), radius=1, color=color.red)
- ground=box(pos=(0,-0.1,0), size=(24,0.2,5),color=color.green)
- accel=vector(0,-9.8,0)
- print ('The acceleration is:', accel)
- ball.velocity=vector(0,0,0)
- dt=0.005
- t=0
- bv=arrow(pos=ball.pos, axis=ball.velocity, color=color.yellow)
- time=0.0
- display2=gdisplay(background=color.white,foreground=color.black)
- poscurve=gcurve(color=color.blue)
- velcurve=gcurve(color=color.orange)
- while t<10:
- time=time+dt
- rate(1.0/dt)
- bv.pos=ball.pos
- bv.axis=ball.velocity
- if ball.pos.y<ground.pos.y+ground.size.y+ball.radius:
- ball.velocity.y=-ball.velocity.y
- ball.velocity=ball.velocity+accel*dt
- ball.pos=ball.pos + ball.velocity*dt
- poscurve.plot(pos=(time,ball.pos.y))
- velcurve.plot(pos=(time,ball.velocity.y))
- print (ball.velocity.y, ball.pos.y)
- t=t+dt
- analyticposcurve=gcurve(color=color.green)
- for taco in range(0,400,1):
- analyticposcurve.plot(pos=(taco/200,(20+0.5*accel.y*taco**2)/200))
Add Comment
Please, Sign In to add comment