% Presntación en vídeo: http://personales.upv.es/asala/YT/V/masmuAnim.html


%run("testEDOsym.mlx") %do this beforehand!
%run("testEDOsymForzada.mlx") %or this!
%We need to have the symbolic expression of the solution
Pos=matlabFunction(posmuelle);%symbolic to numeric function of time

%the spring "shape" to draw
SpringX=[0:0.05:1]; %horiz. coordinates (0: left end, 1: right end)
SpringY=0.8*[0 1 0 -1 0 1 0 -1 0 1 0 -1 0 1 0 -1 0 1 0 -1 0]; %vertical
%The times of the frames
Trange=0:0.05:Tf; N=length(Trange);
for i=1:N
    clf
    p=Pos(Trange(i)); %The solution of the spring ODE to simulate
    xline(0,':m',LineWidth=2)
    patch([-5 -5 6 6],[-1.1 1.1 1.1 -1.1],[.85 .88 .92]) %background
    patch(-5+[-1 -1 0 0],[-4 4 4 -4],[.1 .1 .1]) %draw left box
    yline(-1.1,'k',LineWidth=3), yline(1.1,'k',LineWidth=4) %walls
    hold on
    %draw spring (left end is -5, right end is 4+p)
    plot(-5+SpringX*(4+p),SpringY,'b',LineWidth=3) 
    %draw moving mass
    ShapeX=[-1 -1 -.8 .8 1 1 .8 -.8];
    ShapeY=[-0.8 0.8 1 1 .8 -.8 -1 -1];
    patch(p+ShapeX,ShapeY,'r') %draw moving mass
    xline(p,Color=[.8 .6 .4])
    hold off
    title("vibración longitudinal")
    text(-0.2,1.2,"equilibrio (F(t)=0)",Rotation=90,Color='m')
    axis([-6 6 -2.5 2.5])
    fontsize(gcf,scale=2)
    grid on
    drawnow
    if i==1
        text(2.75,1.25,"Pos. Ini.",Rotation=90)
        pause
    end 
end















