%COMP 236 Programming Assignment 2
%Adrian Ilie, Mar. 2002

function m=makeMovies
sx=200;
sy=200;
nt=50;
t=randomTriangles([sx,sy],nt,0);
sx=ceil(max(max(t(:,1:3))));
sy=ceil(max(max(t(:,4:6))));
nt=size(t);
nt=nt(1);
frame=1;
img=struct('Z',zeros(sy,sx),'R',zeros(sy,sx),'G',zeros(sy,sx),'B',zeros(sy,sx));
for i=1:nt
    img=drawTriangle(img,t(i,:));
    if(mod(i,10)>=0)
        imshow(reshape([img.R img.G img.B],sy,sx,3));
        movie(frame)=getframe;
        frame=frame+1;
    end
end
imwrite(reshape([img.R img.G img.B],sy,sx,3),'random.bmp','bmp');
imshow(reshape([img.R img.G img.B],sy,sx,3));
movie(frame)=getframe;
movie2avi(movie, 'random.avi', 'COMPRESSION', 'None', 'QUALITY', 100);




t=randomTriangles([sx,sy],nt,1);
sx=ceil(max(max(t(:,1:3))));
sy=ceil(max(max(t(:,4:6))));
nt=size(t);
nt=nt(1);
frame=1;
img=struct('Z',zeros(sy,sx),'R',zeros(sy,sx),'G',zeros(sy,sx),'B',zeros(sy,sx));
for i=1:nt
    img=drawTriangle(img,t(i,:));
    if(mod(i,10)>=0)
        imshow(reshape([img.R img.G img.B],sy,sx,3));
        movie0(frame)=getframe;
        frame=frame+1;
    end
end
imwrite(reshape([img.R img.G img.B],sy,sx,3),'randoma.bmp','bmp');
imshow(reshape([img.R img.G img.B],sy,sx,3));
movie0(frame)=getframe;
movie2avi(movie0, 'randoma.avi', 'COMPRESSION', 'None', 'QUALITY', 100);




t=readTriFile('cow.tri');
sx=ceil(max(max(t(:,1:3))));
sy=ceil(max(max(t(:,4:6))));
nt=size(t);
nt=nt(1);
frame=1;
img=struct('Z',zeros(sy,sx),'R',zeros(sy,sx),'G',zeros(sy,sx),'B',zeros(sy,sx));
for i=1:nt
    img=drawTriangle(img,t(i,:));
    if(mod(i,20)==0)
        imshow(reshape([img.R img.G img.B],sy,sx,3));
        movie1(frame)=getframe;
        frame=frame+1;
    end
end
imwrite(reshape([img.R img.G img.B],sy,sx,3),'cow.bmp','bmp');
imshow(reshape([img.R img.G img.B],sy,sx,3));
movie1(frame)=getframe;
movie2avi(movie1, 'cow.avi', 'COMPRESSION', 'None', 'QUALITY', 100);




t=readTriFile('teapot.tri');
sx=ceil(max(max(t(:,1:3))));
sy=ceil(max(max(t(:,4:6))));
nt=size(t);
nt=nt(1);
frame=1;
img=struct('Z',zeros(sy,sx),'R',zeros(sy,sx),'G',zeros(sy,sx),'B',zeros(sy,sx));
for i=1:nt
    img=drawTriangle(img,t(i,:));
    if(mod(i,20)==0)
        imshow(reshape([img.R img.G img.B],sy,sx,3));
        movie2(frame)=getframe;
        frame=frame+1;
    end
end
imwrite(reshape([img.R img.G img.B],sy,sx,3),'teapot.bmp','bmp');
imshow(reshape([img.R img.G img.B],sy,sx,3));
movie2(frame)=getframe;
movie2avi(movie2, 'teapot.avi', 'COMPRESSION', 'None', 'QUALITY', 100);
