%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function 'makeMovieLineDrawing' creates .avi file which contains trace of a point along two linear paths, one with positive 
% slope and the another with negative slope.

% Programmer : Nilesh Ghubade (nileshg@temple.edu)
% Date : Sept 2002
% Advisor : Dr.Longin Jan Latecki (latecki@temple.edu )
% Project : Matlab demonstration
% Department : Computer and Information Science Department, Temple University, Philadelphia, PA-19122, USA

% Input arguments:-
% None

% Output : -
% 1) aviFileName = The name of the .avi file containing the movie of the trace of the point along the linear path.

% Example : -
% 1) [aviFileName] = makeMovieLineDrawing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [aviFileName] = makeMovieLineDrawing

xcoordLine1 = [1:50];
ycoordLine1 = [1:50];

xcoordLine2 = [51:100];
ycoordLine2 = [50:-1:1];

bigMatrixRows = 104;
bigMatrixCols = 104;
smallMatrixRows = 3;
smallMatrixCols = 3;

smallMatrix = ones(smallMatrixRows,smallMatrixCols); % initialize 'smallMatrix' with all 1's.

framesPerSec = 5; % 'frames per second' parameter for the .avi file.

aviFileName = 'DotInMotion';

%aviobj = avifile(aviFileName,'fps',framesPerSec,'COMPRESSION','NONE'); % initialize .avi file object.
aviobj = avifile(aviFileName,'fps',framesPerSec); % initialize .avi file object.


% for loop for creating each frame of the .avi file.
for count=1:100
    bigMatrix = zeros(bigMatrixRows,bigMatrixCols);
    if ((count >= 1) & (count <= 50))
        leftTopColumn = xcoordLine1(count);
        leftTopRow = ycoordLine1(count);
    else
        leftTopColumn = xcoordLine2(count-50);
        leftTopRow = ycoordLine2(count-50);
    end
    position(1) = leftTopRow;
    position(2) = leftTopColumn;
    [bigMatrix] = imposingSmallMatOntoBigMat(smallMatrix,bigMatrix,position); % this function superimposes 'smallMatrix' onto 'bigMatrix'
                                % at given position with respect to the left-top corner of 'smallMatrix'.
                                
    % all 3 color intensities (red, green and blue) of 'bigMatrix' are given same values to form a true color image.                                
        bigMatrixImg(:,:,1) = bigMatrix;
        bigMatrixImg(:,:,2) = bigMatrix;
        bigMatrixImg(:,:,3) = bigMatrix;

        if ((1 <= count) & (count <= 9))
             imageFileNamePrefix = 'framedump_0000';
        else if ((10 <= count) & (count <= 99))
                 imageFileNamePrefix = 'framedump_000';
            else imageFileNamePrefix = 'framedump_00'; 
            end
        end

        fileName = strcat(imageFileNamePrefix,num2str(count),'.bmp');
 

        imwrite(bigMatrixImg,fileName,'bmp');
        imgObj = imread(fileName,'bmp');
        frameObj = im2frame(imgObj);  
        aviobj = addframe(aviobj,frameObj);
        frame(count) = frameObj;
        delete(fileName);
    end
movie(frame);
aviobj = close(aviobj);
    
