SHARE
TWEET

Untitled

a guest Jun 19th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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(radius=1.0, color=color.red, pos=(0,1,0))
  12.  
  13. wallG = box(pos=(0,-0.1,0), size=(24,0.2,5), color=color.green)
  14.  
  15. accel = vector(0,-9.8,0)
  16. ball.velocity = vector(0,15,0)
  17.  
  18. dt=0.05
  19. t=0
  20. display2 = gdisplay(background=color.white, foreground=color.black)
  21.  
  22. poscurve = gcurve(color=color.blue)
  23. velcurve = gcurve(color=color.red)
  24. analposcurve = gcurve(color=color.green)
  25.  
  26. while t < 3.1:
  27.     rate(100)
  28.     ball.velocity = ball.velocity + accel*dt
  29.     ball.pos = ball.pos + ball.velocity*dt
  30.     t = t + dt
  31.  
  32.     poscurve.plot(pos=(t, ball.pos.y))
  33.  
  34.     analposcurve.plot(pos=(t, 1 + 15*t + 0.5*accel.y*t**2))
  35.  
  36.     if ball.pos.y - ball.radius < wallG.pos.y:
  37.         ball.velocity = -ball.velocity
RAW Paste Data
Top