%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function 'sincMovie' creates .avi file which contains 3D-movie of the 'sinc' (sin(r)/r) function using MATLAB graphics functions.
%
% 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 3D-movie of water ripples-like motion.

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

function [aviFileName] = sincMovie
aviFileName = 'sincMovie.avi';
framesPerSec = 5; % 'frames per second' parameter for the .avi file.
aviobj = avifile(aviFileName,'fps',framesPerSec,'COMPRESSION','NONE'); % initialize .avi file object.
frameCount = 1;
[X,Y] = meshgrid(-8:0.5:8); 
R = sqrt(X.^2 + Y.^2) + eps;
for count=1:0.1:2
    Z = sin(R.*count)./(R.*count);
    surf(X,Y,Z,'FaceColor','red','EdgeColor','none');
    grid off;
    axis off;
    camlight left; lighting phong
    %view(-15,65) % (an azimuth of -15 and an elevation of 65 degrees).
    aviobj = addframe(aviobj,getframe);
    movieFrames(frameCount)=getframe;
    frameCount = frameCount + 1;
end
movie(movieFrames);
aviobj = close(aviobj);
return;