function gif_animation ( )

%*****************************************************************************80
%
%% gif_animation() creates an animation as a GIF file.
%
%  Discussion:
%
%    No, anything but GIF.  That GODAWFUL IMAGE FORMAT.
%    But that's the only animation format I can find that allows me to
%    create a sequence of PNG files and merge them.  My failures are too
%    hideous to recall.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 September 2024
%
%  Author:
%
%    John Burkardt
%
  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'gif_animation():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Create a sequence of graphic figures.\n' );
  fprintf ( 1, '  Save each one to a png file.\n' );
  fprintf ( 1, '  Use "convert()" to create a gif animation.\n' );

  x = linspace ( 0, 10, 101 );
%
%  Generate 50 frames.
%
  for p = 1 : 50
    f = figure ( "visible", "off" );
    k = p / 10.0;
    y = cos ( k * x );
    plot ( x, y, 'linewidth', 3 );

    grid ( 'on' );
    xlabel ( "x" );
    ylabel ( "y" );
    title_str = sprintf ( '{y=cos({%.2f}*x)}', k );
    title ( title_str );
%
%  Save each figure to a file.
%
    filename = sprintf ( '%05d.png', p );
    print ( '-dpng', filename );

  end
%
%  Use Imagemagick "convert()" to merge png images into a gif.
%
  system ( "convert -delay 10 -loop 0 *.png output.gif" );
  system ( "rm *.png" );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Animation created as "output.gif"\n' );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'gif_animation():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  timestamp ( );

  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
 
