function make_frame ( frame_id, frame_max )

%*****************************************************************************80
%
%% make_frame() makes a particular frame of an animation.
%
%  Discussion:
%
%    Making frames from 0 to frame_max will create a sequence of JPG
%    files that constitute the frames of an animation, in which a
%    "hilly" plot gradually flattens out.
%
%    QUICKTIME is one program that can collect these individual frames into
%    a single animation file.
%
%    The value of frame_max does not really limit the possible values
%    of FRAME_ID.  It is simply the value at which the plot first returns to
%    its initial state.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 March 2010
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer FRAME_ID, the index of the frame to be created.
%
%    integer frame_max, the index of the last frame in the sequence.
%

%
%  PEAKS returns a 49 x 49 matrix of data that can be plotted
%  as a surface.
%
  Z = peaks ( );
%
%  Scale the data so that it completes a cycle on frame frame_max.
%
  scale = cos ( 2.0 * pi * frame_id / frame_max );
%
%  Plot the data as a surface plot, and color it based on the
%  unscaled data.
%
  surf ( scale * Z, Z, 'EdgeColor', 'Interp', 'FaceColor', 'Interp' )
%
%  Go through a horizontal rotation of 5 degrees per frame.
%
  az = 5.0;
  az = frame_id * 5.0;
  el = 40.0;
  view ( az, el );
%
%  Force all frames to share the same axis.
%
  axis ( [ 0, 50, 0, 50, -10, +10 ] );
%
%  Create a filename that is unique for this frame.
%
  filename = sprintf ( 'frame%04d.jpg', frame_id );

  title ( filename );
  xlabel ( '--X--' );
  ylabel ( '--Y--' );
  zlabel ( '--Z--' );
%
%  Save the graphics current figure (GCF) as a "frame".
%
  f = getframe ( gcf );
%
%  Extract the image and color map.
%
  [ image, colormap ] = frame2im ( f );
%
%  Have frame 0 save the color map to a MAT file.
%
  if ( frame_id == 0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, '  Colormap saved as "colormap.mat"\n' );
    save ( 'colormap.mat', 'colormap' );
  end
%
%  Write the image data.
%
  imwrite ( image, filename, 'JPG' )

  return
end
 
