% Driver for cellular automata function 'ca'
%
% Only use rules where dead cell in dead neigbourhood remains dead, i.e.
% even-numbered rules

for rule = 2 : 2 : 62
   nsite = 1000;
   ngen = 1000;
   % For each rule, run with both types of initial conditions (single
   % central site alive and random) ...
   for initopt = 0 : 1
      % Perform the evolution ...
      [c, x, y] = ca(rule, nsite, ngen, initopt);
      % Check to see whether there's anything to plot ...
      if sum(size(c)) ~= 0 
         clf;
         % Generate a title that reflects the type of initial conditions ...
         if initopt == 0
            stitle = ...
               sprintf('Rule %d: Initial Conditions: Center Site Alive', rule);
         else
            stitle = sprintf('Rule %d: Initial Conditions: Random', rule);
         end
         % ... and plot the results 
         plot(x, y, '.r', 'Markersize', 1);
         title(stitle);
         axis('square');
         input('Type ENTER to continue: ');
      end
   end
end

% Generate and plot 100 evolutions using random initial conditions and 
% the "very interesting" rule 20
for n = 1 : 100
   % Perform the evolution ... 
   [c, x, y] = ca(20, 300, 300, 1);
   % ... and plot the results
   clf;
   plot(x, y, 'or', 'Markersize', 3);
   title('Rule 20: Initial conditions: Random');
   axis('square');
   input('Type ENTER to continue: ');
end

