%EE683 Group Project
%Ting-Hsiang Chuang


clc
clear all
close all

fid = fopen('threefireflies.txt');  %load the data file

i=1;                             %initialize variable i


while 1
    
   curlin=fgetl(fid);

   if curlin(1) ~= 'T'  %if the first character is not t
       
      if ~ischar(curlin)    %if it is not a character 
       
          break             %stop reading
          
      end
      
     
      
      
    T(i,:)=str2num(curlin(1:4));      %store the time in second
    
    
    A(i,:)=str2num(curlin(16:23));    
    B(i,:)=str2num(curlin(31:38));    
    C(i,:)=str2num(curlin(46:53));   
  
    
    if A(i,:)>=0.65
        A(i,:)=1;
    else
        A(i,:)=0;
    end
    
    
    
    

    
    if B(i,:)>=0.65
        B(i,:)=1;
    else
        B(i,:)=0;
    end
    

    
    if C(i,:)>=0.65
        C(i,:)=1;
    else
        C(i,:)=0;
    end
    
    i=i+1;                 
    
   end

end


fclose(fid)



ida=find(A(:)==1);
idb=find(B(:)==1);
idc=find(C(:)==1);

ta=T(ida);         % at the time where A=1 (on)
tb=T(idb);
tc=T(idc);



x=[0:0.01:10]';  %new time axis
ya=zeros(length(0:0.01:10),1);
yb=zeros(length(0:0.01:10),1);
yc=zeros(length(0:0.01:10),1);

for i=1:length(ya)
    
    for j=1:length(ta)
        
        if x(i)==ta(j)
           ya(i)=1;
        end

    end
    
    
    for j=1:length(tb)
        
        if x(i)==tb(j)
            yb(i)=1;
        end
        
    end
    
    for j=1:length(tc)
        
        if x(i)==tc(j)
            yc(i)=1;
        end
        
    end
    
end


%  cwd = pwd;
%  cd(tempdir);
%  pack
%  cd(cwd)

n = -180:180;
t = sin(n*pi/180);
v = cos(n*pi/180);

% Define the area to be recorded
rect = get(gcf,'Position');
rect(1:2) = [0 0];

m=1;

for xx=1:length(ya)
   
    tt(m,:)=x(xx,:);
    yya(m,:)=ya(xx,:);
    yyb(m,:)=yb(xx,:);
    yyc(m,:)=yc(xx,:);
    
    
subplot(331)
if yya(m)==1
    a=fill(t,v,'g');
else
    a=fill(t,v,'w');
end
axis off


% subplot(334)
% plot(tt,yya,'g')
% axis([0 10 0 1.2])


subplot(332)
if yyb(m)==1
    b=fill(t,v,'g');
else
    b=fill(t,v,'w');
end
axis off


% subplot(335)
% plot(tt,yyb,'r')
% axis([0 10 0 1.2])


subplot(333)
if yyc(m)==1
    c=fill(t,v,'g');
else
    c=fill(t,v,'w');
end
axis off


% subplot(336)
% plot(tt,yyc,'b')
% axis([0 10 0 1.2])
    

M(m)=getframe(gcf,rect);

m=m+1;
end

map=colormap;

mpgwrite(M, map,'movie3')
