Guest User

Untitled

a guest
Dec 13th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. from visual import *
  2. from visual.graph import *
  3.  
  4. scene.width=800
  5. scene.height=800
  6. scene.range=(16,16,16)
  7. scene.autoscale = 0
  8. scene.center=(0,12,0)
  9. scene.background=color.white
  10.  
  11. ball = sphere(pos=(0,20,0), radius=1, color=color.red)
  12. ground=box(pos=(0,-0.1,0), size=(24,0.2,5),color=color.green)
  13. accel=vector(0,-9.8,0)
  14.  
  15.  
  16. print ('The acceleration is:', accel)
  17.  
  18. ball.velocity=vector(0,0,0)
  19. dt=0.005
  20. t=0
  21.  
  22. bv=arrow(pos=ball.pos, axis=ball.velocity, color=color.yellow)
  23. time=0.0
  24. display2=gdisplay(background=color.white,foreground=color.black)
  25. poscurve=gcurve(color=color.blue)
  26. velcurve=gcurve(color=color.orange)
  27. while t<10:
  28.     time=time+dt
  29.     rate(1.0/dt)
  30.     bv.pos=ball.pos
  31.     bv.axis=ball.velocity
  32.     if ball.pos.y<ground.pos.y+ground.size.y+ball.radius:
  33.             ball.velocity.y=-ball.velocity.y
  34.     ball.velocity=ball.velocity+accel*dt
  35.     ball.pos=ball.pos + ball.velocity*dt
  36.     poscurve.plot(pos=(time,ball.pos.y))
  37.     velcurve.plot(pos=(time,ball.velocity.y))
  38.     print (ball.velocity.y, ball.pos.y)
  39.    
  40.     t=t+dt
  41. analyticposcurve=gcurve(color=color.green)
  42. for taco in range(0,400,1):
  43.     analyticposcurve.plot(pos=(taco/200,(20+0.5*accel.y*taco**2)/200))
Add Comment
Please, Sign In to add comment