4
$\begingroup$

In animating a 2D cellular automata like this:

    Animate[ArrayPlot[CellularAutomaton[20, {{1}, 0}, {n, All}], 
  Mesh -> True] , {n, 0, 20, 0}, AnimationRunning -> False]

The animation displays each iteration and the grid is expanding. Is there instead a way to animate the cellular automation while seeing the entire grid at all times? Similar to the point of view in the animation of game of life on Wikipedia.

$\endgroup$
0

2 Answers 2

7
$\begingroup$
m = 20;

Animate[ArrayPlot[ArrayPad[CellularAutomaton[20, {{1}, 0}, {n, All}], 
    {{0, m - n}, {m - n, m - n}}], Mesh -> True], 
 {n, 0, m, 1}, AnimationRunning -> False]

enter image description here

$\endgroup$
5
$\begingroup$

You can use PadRight and PadLeft to pad the matrix with zeroes.

One possible solution is

Module[{rule = 20, max = 20, ca},
 ca = CellularAutomaton[rule, {{1}, 0}, {max, All}];
 Animate[
  ArrayPlot[
   (* Display only the first n rows of ca and pad the rest with zeroes *)
   PadRight[ca[[;; n]], {max + 1, 2 max + 1}],
   Mesh -> True
   ], {n, 1, max, 0}, AnimationRunning -> False]
 ]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.