%
%  Making movies: motion of four masses connected with springs
%             Victor Matveev, June 1 2010
%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

IC=[-1 2 3 -4 2 4 -2 -4];
[T, Y] = ode45(@spring4,[0 25], IC);

L=20;
for i=1:length(T);

    hold off;
    plot([Y(i,1) Y(i,2)+L], [10 10],'g-')
    hold on;
    plot([Y(i,2)+L Y(i,3)+2*L], [10 10],'r-')
    plot([Y(i,3)+2*L Y(i,4)+3*L], [10 10],'b-')
    
    plot(Y(i,1),    10,'o','markersize',10,'markerfacecolor','red');
    plot(Y(i,2)+L,  10,'o','markersize',10,'markerfacecolor','blue');
    plot(Y(i,3)+2*L,10,'o','markersize',10,'markerfacecolor','green');
    plot(Y(i,4)+3*L,10,'o','markersize',10,'markerfacecolor','black');
    
    axis([-10 70 0 20]);
    title('Four masses connected with springs');
    drawnow;
    pause(0.02)

end;
