from visual import * from helix import * from visual.graph import * L=0.1 #unstretched length of the spring A=L/2. #amplitude of the oscillation scene.autoscale=0 scene.range=1.2*L scene.background=color.white #put the wall at -L so that the other end of the spring is at the origin when unstretched wall=box(pos=vector(-L,0,0), width=L/2., height=L/2., length=L/20., color=color.red) #put the object at the position x=A so that the spring is initially stretched an amount A mass=cylinder(pos=vector(A,0,0), axis=vector(L/20.,0,0), radius=L/10., color=(0.5,0.5,0.5)) spring=helix(pos=wall.pos, axis=mass.pos-wall.pos, radius=L/10., color=(1,0.7,0.2), thickness=L/100.) xaxis=arrow(pos=vector(0,0,0), axis=vector(L,0,0), color=color.black, shaftwidth=L/50.) yaxis=arrow(pos=vector(0,0,0), axis=vector(0,L,0), color=color.black, shaftwidth=L/50.) graph=gdisplay(x=0,y=0,width=400, height=400, title='x vs t for object oscillating on a spring', xtitle='t (s)', ytitle='x (m)', xmax=2, ymax=1.1*A, ymin=-1.1*A, background=color.black) function=gcurve(color=color.magenta) mass.m=0.1 mass.v=vector(0,0,0) mass.p=mass.m*mass.v #spring constant k=20 dt=0.001 t=0 while t<2: rate(100) s=mass.pos Fnet= #YOU MUST FILL IN THIS LINE mass.p= #YOU MUST FILL IN THIS LINE mass.pos= #YOU MUST FILL IN THIS LINE spring.modify(axis=mass.pos-spring.pos) t=t+dt function.plot(pos=(t,mass.pos.x))