%
%   
disp(' ');
disp(' SDOF_sine7.m   ver 1.0   August 30, 2004 ');
disp(' by Tom Irvine  Email: tomirvine@aol.com ');
disp(' ');
disp(' This program generates an animation of seven single-degree-of-freedom ');
disp(' systems subjected to sinusoidal base excitation. ');
%
clear all
nframes = 20;
%
%
refresh;
    w=1.;
    h=1.;
    hb=0.2;
    x=1;
%    
    xs=x+w/2.;
    X(1,1)=xs;
    X(1,2)=xs;
    X(1,3)=xs-0.15;  
    X(1,4)=xs+0.15;
    X(1,5)=xs-0.15;
    X(1,6)=xs+0.15; 
    X(1,7)=xs-0.15;
    X(1,8)=xs+0.15;
    X(1,9)=xs;
    X(1,10)=xs;
%
    for i=2:7
        for j=1:10
            X(i,j)=X(i-1,j)+1.5;  
        end
    end
%
%    disp(' ');
%    fn=input(' Enter natural frequency (Hz) ');
%    disp(' ');
%    f =input(' Enter excitation frequency (Hz) ');	
%    disp(' ');
%    damp =input(' Enter the damping ratio (typically 0.05) ');	   
%
    f=1.;
    fn(1)=0.50;
    fn(2)=0.63;
    fn(3)=0.80;
    fn(4)=1.00;
    fn(5)=1.25;
    fn(6)=1.60;
    fn(7)=2.00;   
%    
    damp=0.05;
%
    for jk=1:7
        rho=f/fn(jk);
    %
        aa=1.+(2.*damp*rho)^2;
        bb=(1.-rho^2)^2+(2.*damp*rho)^2;
        trans(jk)=sqrt(aa/bb);
%    
        aa=2.*damp*rho^3;
        bb=1.+rho^2*(4.*damp^2-1);
        phase(jk)=atan(aa/bb);
%    
    end
%
    A=0.2;
%    
    rectangle('Position',[0,0,12,9],'FaceColor','w','EraseMode','background'); 
for k=1:nframes
    T=1.;
    dt=1./nframes;
    t=(k-1)*dt;
%
    yb(k)=1.0 +  A*sin(2*pi*t*f);
%      
    xr=x;
    for jk=1:7        
        y(jk,k) =3.5 +  A*trans(jk)*sin(2*pi*t*f-phase(jk));
        HH(jk)=rectangle('Position',[xr,y(jk,k),w,h],'FaceColor',[0 0.6 0.6],'EraseMode','xor');       
        xr=xr+1.5;
%
        d=y(jk,k)-yb(k)-hb;
        delta=d/8.;
%    
        Y(1)=yb(k)+hb;
        Y(2)=Y(1)+delta;
        Y(3)=Y(2)+delta/2.;
        Y(4)=Y(3)+delta;
        Y(5)=Y(4)+delta;
        Y(6)=Y(5)+delta;
        Y(7)=Y(6)+delta; 
        Y(8)=Y(7)+delta;
        Y(9)=Y(8)+delta/2.;    
        Y(10)=Y(9)+delta;   
%    
        LL(jk)=line(X(jk,:),Y,'EraseMode','xor','Color',[0 0.2 0.5]);   
    end
%    
%    
    h2=rectangle('Position',[x,yb(k),w+9,hb],'FaceColor',[0.2 0.2 0.2],'EraseMode','xor');      
    drawnow;
    pause(0.5);
    M(k)=getframe;
    delete(HH);
    delete(h2);
    delete(LL);
end    
movie(M,24);
%
%
%   disp(' ');
%   disp(' Enter the output movie filename: ');
%   output_filename = input(' ','s');
%
% movie2avi(M,output_filename,'quality',100);


