GlowScript 2.7 VPython
scene.width = 800
scene.height = 600
scene.center = vector(10, 15, 0)

## Add Cliff, Ground, and Cart objects
Cliff = box(pos=vector(-10,20,0), size=vec(20,40,1))
Ground = box(pos=vector(10,-1,0), size=vec(60,2,1), color=color.green)
Cart = box(pos=vector(-20,40.5,0), size=vec(1,1,1), color=color.red, make_trail = True)

## Give the cart and velocity
Cart.velocity=vector(10,0,0)

## The lines below create graphs for height vs time, velocity vs time, and acceleration vs time
Grph1 = graph(title='Height vs Time', xtitle='Time (s)', ytitle='Height (m)', fast=False)
HeightGraph = gcurve(color=color.red, label='Height')

Grph2 = graph(title='Velocity vs Time', xtitle='Time (s)', ytitle='Velocity_y (m/s)', fast=False)
VelocityGraph = gcurve(color=color.blue, label='Velocity_y')

Grph3 = graph(title='Acceleration vs Time', xtitle='Time (s)', ytitle='Acceleration_y (m/s^2)', fast=False)
AccelerationGraph = gcurve(color=color.green, label='Acceleration_y')

## Create time variables
t=0
dt=0.01

while Cart.pos.y > 0:
    rate(1000)
    if Cart.pos.x<0:
        Cart.acceleration=vector(0,0,0)
        Cart.pos=Cart.pos+Cart.velocity*dt
#    else:
#        Cart.acceleration=vector(0,-9.8,0)
#        Cart.velocity=Cart.velocity+Cart.acceleration*dt
#        Cart.pos=Cart.pos+Cart.velocity*dt
        
    ## The line below updates the graphs
    HeightGraph.plot(t,Cart.pos.y)
    VelocityGraph.plot(t,Cart.velocity.y)
    AccelerationGraph.plot(t,Cart.acceleration.y)
    
    t=t+dt
  • summer_2019/2d_motion.txt
  • Last modified: 2019/08/07 20:05
  • by wellerd