function cc_levels_minmax_animate ( )

%*****************************************************************************80
%
%% CC_LEVELS_MINMAX_ANIMATE displays the sequence of grids generated by CC_LEVELS_MINMAX.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    15 November 2006
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'CC_LEVELS_MINMAX_ANIMATE:\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Display the sequence of nested 2D Clenshaw-Curtis grids\n' );
  fprintf ( 1, '  generated by CC_LEVELS_MINMAX.\n' );

  dim_num = 2;
 
  while ( 1 )
%
%  Get user input.
%
    fprintf ( 1, '\n' );
    level_max = input ( 'Enter LEVEL_MAX or RETURN to exit;' );
    
    if ( isempty ( level_max ) )
      break
    end

    grid_points_old = [];
    grid_points_old_num = 0;

    grid_points = [];
    grid_points_num = 0;

    for level = 0 : level_max

      if ( 0 < grid_points_num )

        grid_points_old(1:2,grid_points_old_num+1:grid_points_old_num+grid_points_num) = ...
          grid_points(1:2,1:grid_points_num);

        grid_points_old_num = grid_points_old_num + grid_points_num;

      end
%
%  Compute data.
%
      [ grid_num, point_num ] = cc_levels_minmax_size ( dim_num, ...
        level, level );
    
      [ grid_level, grid_order, grid_points ] = cc_levels_minmax ( dim_num, ...
        level, level,  grid_num, point_num );

      [ dim_num, grid_points_num ] = size ( grid_points );

      clf
%
%  We have to name the axes in order to control the grid.
%
      axes_handle = axes;
%
%  Plot the points.
%
      handle_new = scatter ( grid_points(1,:), grid_points(2,:), 'r', 'filled' );

      hold on

      if ( 0 < grid_points_old_num )
        handle_old = scatter ( grid_points_old(1,:), grid_points_old(2,:), 'b', 'filled' );
      end
%
%  Force the plotting region to be square, not rectangular.
%
      axis square
%
%  Request grid lines.
%
      grid on
%
%  Specify the location of the grid lines, and suppress labeling.
%
      set ( axes_handle, 'xtick', [ -1, -.75, -.5, -.25, 0, .25, .50, .75, 1] );
      set ( axes_handle, 'xticklabel', [] );
      set ( axes_handle, 'ytick', [ -1, -.75, -.5, -.25, 0, .25, .50, .75, 1] );
      set ( axes_handle, 'yticklabel', [] );
%
%  Make the plotting region slightly bigger than the data.
%
      axis ( [ -1.1, 1.1, -1.1, 1.1 ] )
%
%  Title
%
      s = sprintf ( '+LEVEL %d', level );
      title ( s );

      fprintf ( 1, '+LEVEL %d, Press return\n', level );
      pause

      hold off

    end

    fprintf ( 1, 'Press return to CLEAR the grid!\n' );
    pause
    clf

  end

  fprintf ( 1, '\n' );
  fprintf ( 1, 'CC_LEVELS_MINMAX_ANIMATE:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  fprintf ( 1, '\n' );
  timestamp ( );

  return
end
