function SDOF_base_animation_function(th,yb,y,plot_title)
%   
disp(' ');
disp(' SDOF_base_animation_function.m   ver 1.0   November 7, 2006 ');
disp(' by Tom Irvine  Email: tomirvine@aol.com ');
disp(' ');
disp(' This program generates an animation of a single-degree-of-freedom ');
disp(' system subjected to sinusoidal base excitation. ');
%
nframes=(length(th));
kend=nframes;
yy=y;
ymax=max(yy);
offset=ymax*1.5;
if(offset<4)
    offset=4;
end
y=yy+offset;
yup=max(y)*1.3;
%
bbb=0.5;
xbase=[-0.5,-0.5,0.5,0.5]; % plotting coordinates of base
%
xmass=xbase; % plotting coordinates of mass
%
iflag=1;
while(iflag==1)
%
    ccc=(yup-min(yb))/6;
    bbb=ccc/8;
%
    if(bbb<0.5)
        bbb=0.5;
        ccc=bbb*8;
        yup=5*ccc+min(y);
    end
    if(yup< (0.9*max(y)+ccc))
        yup=yup*1.1
    else
        iflag=0;
    end
end
offset=(yup-ccc)/2;
%
ylow=min(yb)-2*bbb;
%
y=yy+offset;
%
ybase=[-bbb,bbb,bbb,-bbb];
ymass=[0,ccc,ccc,0];
%
for k=1:kend
%
    distance=y(k)-(yb(k)+bbb);
%
    x1(k)=0.;
    x2(k)=0.;
    x3(k)=-0.25;
    x4(k)=+0.25;
    x5(k)=-0.25;
    x6(k)=+0.25;
    x7(k)=-0.25;
    x8(k)=+0.25;
    x9(k)=0.;
    x10(k)=0.;        
    dyf=distance/8;
    dyh=dyf/2;
%
    y1(k)=yb(k);
    y2(k)=y1(k)+dyf;
    y3(k)=y2(k)+dyh;
    y4(k)=y3(k)+dyf;
    y5(k)=y4(k)+dyf;
    y6(k)=y5(k)+dyf;
    y7(k)=y6(k)+dyf;
    y8(k)=y7(k)+dyf;
    y9(k)=y8(k)+dyh;
    y10(k)=y9(k)+dyf; 
end
%
y1=y1+bbb;
y2=y2+bbb;
y3=y3+bbb;
y4=y4+bbb;
y5=y5+bbb;
y6=y6+bbb;
y7=y7+bbb;
y8=y8+bbb;
y9=y9+bbb;
y10=y10+bbb;
%
L0=3;
Hf=figure('Units','normalized','Position',[.1,.1,.8,.4]);
%
Ha_f2a2=subplot(1,4,1);
%
Hp_patch_base=patch(xbase,ybase,[0 0.2 0.2]);
Hp_patch_mass=patch(xmass,ymass,[0 0.5 0.5]);
%
k=1;
hspring=line([x1(k) x2(k) x3(k) x4(k) x5(k) x6(k) x7(k) x8(k) x9(k) x10(k)],[y1(k) y2(k) y3(k) y4(k) y5(k) y6(k) y7(k) y8(k) y9(k) y10(k)],'color','k','linewidth',2);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
axis([-2,2,ylow,yup]),grid on 
%
Ha_f2a1=subplot(1,4,2:4);
%
Hls_f2plot1=plot(th(1),yb(1),th(1),y(1));axis([min(th),th(end),-2,yup]),grid on,...
   xlabel('t (sec)')  
%
clear figure;
refresh;
figure(1);
clear F;
set(gcf,'DoubleBuffer','on');
for k=1:kend    
%
     plot(th(1:k),yb(1:k),th(1:k),(y(1:k)+ccc/2));axis([min(th),th(end),ylow,yup]),grid on,...
   xlabel('time (sec)'),title(plot_title)  
%
    set(hspring,'XData',[x1(k) x2(k) x3(k) x4(k) x5(k) x6(k) x7(k) x8(k) x9(k) x10(k)],'YData',[y1(k) y2(k) y3(k) y4(k) y5(k) y6(k) y7(k) y8(k) y9(k) y10(k)]);
    set(Hp_patch_base,'YData',ybase+yb(k)); 
    set(Hp_patch_mass,'YData',ymass+y(k));    
    if(k==1)
        pause(2);  
    else
        pause(0.1);        
    end
%    F(k)=getframe;
    drawnow;
end    