
%------------------------------------------------------

% define the vertices of a square lying in the xy plane
v = [
  -1   1   1  -1
  -1  -1   1   1
   0   0   0   0
   1   1   1   1
];
% draw a green patch using these vertices
h = patch(v(1,:)', v(2,:)', v(3,:)', [.5 .7 .5]);

%------------------------------------------------------

% create the avi file and set its parameters
video = avifile( ...
  'changeview.avi','fps', 10, 'keyframe', 10, ...
  'quality', 100, 'compression', 'none' ...
);
frames = 75;

% set the units of the current axes to pixels, for use with getframe
set(gca, 'Units', 'pixels');

% set the appearance of the current axes
axis([-1 1 -1 1 -1 1], 'square'); box on; grid on;

% render frames while changing the viewpoint
azimuth = -60; elevation = 60;
for (i = 1:frames)
  view(azimuth, elevation);
  azimuth = azimuth - 1 ; elevation = elevation - .5;

  % obtain [left, bottom, width, height] of the current axes
  rect = get(gca, 'Position');
  % get a frame of that size, relative to the current figure
  frame = getframe(gcf, rect);
  % add it to the avi file as usual
  video = addframe(video, frame);
end
video = close(video); % finis
