x# = 150.0 :` starting position m# = 10.0 :` mass R# = 150 :` resting length K# = 0.6 :` spring coefficient v# = 0.0 :` velocity f# = 0.9 :` friction backdrop on color backdrop 0 sync on sync rate 60 dim points(12,1) repeat if mousex() > x#-10 and mousex() < x#+10 and flag = 0 and mouseclick() mx# = mousex() - x# flag = 1 endif if flag = 1 and mouseclick() x# = mousex() - mx# else flag = 0 force# = -k# * (x#-R#) v# = (v# + force#/m#)*f# x# = x# + v# endif ink rgb(120,120,0),0 box R#-10,230,R#+10,250 ink rgb(255,255,255),0 box x#-10,230,x#+10,250 rem draw spring h# = (R#/x#)*20 if h# > 20 then h# = 20 offset = x#/12 for t = 1 to 12 if t mod 2 = 0 y = h# else y = -h# endif points(t,0) = offset*t points(t,1) = 240+y next t line 0,240,points(1,0),points(1,1) for i = 1 to 12 j = i+1 if i = 12 line points(i,0),points(i,1),x#,240 else line points(i,0),points(i,1),points(j,0),points(j,1) endif next i rem end draw spring set cursor 0,0 print "force: ",force# print "pos: ",x# sync until spacekey() end