function cvt_corn_movie ( it_max, nb, ni, np, ns, pr_bud, pr_bud_angular, r )

%*****************************************************************************80
%
%% cvt_corn_movie() models the growth of a corn kernel.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 January 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer IT_MAX: the maximum number of iterations.
%
%    integer NB, the number of boundary points.
%
%    integer NI, the number of interior points.
%
%    integer NP, the total number of points.
%
%    integer NS, the number of sample points.
%
%    real PR_BUD, the probability that a boundary point will bud.
%
%    real PR_BUD_ANGULAR, the probability that a boundary point bud
%    will be constrained to the boundary.
%
%    real R: the radius of the circle that represents the corn kernel.
%
%  Local:
%
%    integer IT: the current iteration index.
%
%    integer P_TYPE(NP): the "type" of each generator.
%    1, the point is constrained to the boundary of the disk.
%    2, the point is constrained to the disk.
%
%    real P_XY(2,NP): the location of the generators.
%
%    real R_MAX: the radius of the plot region.
%
  r_max = 2.5 * r;
%
%  Open the movie file.
%
  moviename = 'cvt_corn_movie.avi';
  V = VideoWriter ( moviename, 'Motion JPEG AVI' );
  FrameRate = 5;
  FrameRate = 2;
  V.FrameRate = FrameRate;
  open ( V );
%
%  Carry out steps 0 through IT_MAX of the iteration.
%
  for it = 0 : it_max

    if ( it == 0 )
      [ p_xy, p_type ] = state_initialize ( nb, ni, np, r );
    else
      [ nb, ni, np, p_xy, p_type ] = bud ( pr_bud, pr_bud_angular, r, ...
        nb, ni, np, p_xy, p_type );

      [ r, p_xy, p_type ] = radial_growth ( r, np, p_xy, p_type );
      if ( r_max <= r )
        r_max = 1.5 * r;
      end

      p_xy = cvt_disk ( r, ns, np, p_xy, p_type );
    end

    header = sprintf ( ...
      'CVT step %d, with %d boundary, %d interior, R = %g', it, nb, ni, r );
    cvt_display ( r, r_max, p_xy, p_type, header );
%
%  Extract the graphics information as a frame,
%  and add it to the movie.
%
    frame = getframe ( 1 );
    writeVideo ( V, frame );

  end

  close ( V );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Movie saved as "%s"\n', moviename );

  return
end

