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

% 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 and appearance of the current axes
set(gca, ...
  'Units', 'pixels', ...
  'DataAspectRatio', [1 1 1], 'DataAspectRatioMode', 'manual', ...
  'Box', 'on', 'TickLength', [0 0], ...
  ...
  'XGrid', 'on', 'XLim', [-1 1], 'XLimMode', 'manual', ...
  'XTick', [-1 -0.5 0 0.5 1], 'XTickLabel', [], ...
  'XTickLabelMode', 'manual', 'XTickMode', 'manual', ...
  ...
  'YGrid', 'on', 'YLim', [-1 1], 'YLimMode', 'manual', ...
  'YTick', [-1 -0.5 0 0.5 1], 'YTickLabel', [], ...
  'YTickLabelMode', 'manual', 'YTickMode', 'manual', ...
  ...
  'ZGrid', 'on', 'ZLim', [-1 1], 'ZLimMode', 'manual', ...
  'ZTick', [-1 -0.5 0 0.5 1], 'ZTickLabel', [], ...
  'ZTickLabelMode', 'manual', 'ZTickMode', 'manual' ...
);

% 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
