function polygon_average_test ( )

%*****************************************************************************80
%
%% polygon_average_test() tests polygon_average().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    25 February 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../polygon_average' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'polygon_average_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  polygon_average() repeatedly averages the vertices of a polygon.\n' );
%
%  Define the starting polygon.
%
  n = 10;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of vertices will be %d\n', n );

  p = 2.0 * rand ( n, 2 ) - 1.0;

  figure ( 1 );
  clf ( );
  plot ( [ p(1:n,1); p(1,1) ], [ p(1:n,2); p(1,2) ], 'Color', 'b', 'Marker', 'o' );
  grid ( 'on' );
  axis ( [ -1.0, 1.0, -1.0, 1.0 ] );
% axis ( 'equal' );
  title ( 'Original polygon', 'Fontsize', 16 );
  filename = 'polygon_original.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Repeatedly average the vertices.
%
  for step = 1 : 20

    p2 = polygon_average ( n, p );

    figure ( 2 );
    clf ( );
    hold ( 'on' );
      plot ( [ p(1:n,1); p(1,1) ], [ p(1:n,2); p(1,2) ], ...
        'Color', 'b', 'Marker', 'o' );
      plot ( [ p2(1:n,1); p2(1,1) ], [ p2(1:n,2); p2(1,2) ], ...
        'Color', 'r', 'Marker', 'o', 'LineWidth', 3 );
    hold ( 'off' );
    grid ( 'on' );
    axis ( [ -1.0, 1.0, -1.0, 1.0 ] );
%   axis ( 'equal' );
    string = sprintf ( 'Step %d\n', step );
    title ( string, 'Fontsize', 16 );


    p = p2;
%
%  Wait one second.
%
    pause ( 1.0 );

  end
%
%  Save an image of the last polygon.
%
  filename = 'polygon_average.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'polygon_average_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../polygon_average' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

