d2 x(t) -k*x ------- = ------ dt2 M
1 store the value of x in the sine at position t 1b t=t+1 2 a=-k*x 3 v=v+a/M*dt (make dt=1 ;) 4 x=x+v 5 check if x is -1 again ,in which case the sine ends and the loop stops.. (a better check would be that x< -0.99 and speed is negative or something)