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

function m=main
sx=200;
sy=200;
nt=1000;
%t=randomTriangles([sx,sy],nt,1);
%t=readTriFile('hexcone.tri');
%t=readTriFile('cow.tri');
t=readTriFile('teapot.tri');

sx=ceil(max(max(t(:,1:3))));
sy=ceil(max(max(t(:,4:6))));
nt=size(t);
nt=nt(1);

mytime=zeros(nt,7);
counter=1;
img=struct('Z',zeros(sy,sx),'R',zeros(sy,sx),'G',zeros(sy,sx),'B',zeros(sy,sx),'T',zeros(1,7));
for i=1:nt
    img=drawTriangleT(img,t(i,:));
    if(mod(i,40)==0)%show every 4th frame
        imshow(reshape([img.R img.G img.B],sy,sx,3));
    end
    mytime(counter,:)=img.T(1:7);
    counter=counter+1;
end

X=[ones(nt,1) mytime(:,6:7)];
val=sum(mytime(:,1:5),2);
a=X\val;
Y=X*a;
a
maxe=max(abs(Y-val))

m=[a' maxe];