function cellular_automaton_plot ( cell_num, step_num, x )

%*****************************************************************************80
%
%% cellular_automaton_plot() plots the evolution of the rule #30 cellular automaton.
%
%  Discussion:
%
%    Given an initial linear array of 0's and 1's, rule 30 produces a new
%    array using the rules:
%
%      111  110  101  100  011  010  001  000
%       V    V    V    V    V    V    V    V
%       0    0    0    1    1    1    1    0     
%
%    Note that there are 256 = 2^8 possible ways to fill in this output
%    chart, and that rule 30 gets its index by the fact that
%    (0,0,0,1,1,1,1,0) can be interpreted as the binary representation of 30.
%
%    For instance, if the current values of X(4), X(5) and X(6) are
%    0, 1 and 1, respectively, then the new value of X(5) will be 1.
%
%    The first and last entries of the array must be treated specially, since
%    they don't have a left or right neighbor.  Assuming we start with a single
%    1 at the center of the array, we can simply set step_num, the number of
%    steps to take, small enough that the boundary cells never have a chance
%    to affect the computation.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    06 December 2022
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Stephen Wolfram,
%    A New Kind of Science,
%    Wolfram Media, 2002,
%    ISBN13: 978-1579550080,
%    LC: QA267.5.C45.W67.
%
%  Input:
%
%    integer cell_num: the number of cells.
%
%    integer step_num: the number of steps.
%
%    integer x(step_num+1,cell_num): the cellular data.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'cellular_automaton_plot():\n' );
  fprintf ( 1, '  Plot the evolution of the rule #30 cellular automaton.\n' );
%
%  Now plot the results.
%
  clf ( );

  hold ( 'on' );
  radius = 0.35;
  for i = 1 : step_num + 1
    for j = 1 : cell_num
      if ( x(i,j) == 1 )
        circle_ij_fill ( step_num + 1, i, j, radius, 'r' );
%
%  Turn on this option to add open circles corresponding to 0 values.
%
      else
        if ( false )
          circle_ij_outline ( step_num + 1, i, j, radius, 'k' );
        end
      end
    end
  end

  hold ( 'off' );
  axis ( 'off' );
  axis ( 'equal' );

  filename = 'cellular_automaton.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

