# 2D Cellular Automaton: Initial conditions

I'm trying to write in Mathematica for a 20x20 grid, with 100 colours, with 4 neighbours. I want the initial conditions to be a 20x20 matrix consisting mainly of zeros.

CellularAutomaton[{100 (4 (100 - 1) + 1), {100, 1}, {1, 1}},
MatrixForm[Table[RandomInteger[], {20}, {20}]], 1]


Apparently init is not in the right form?

• If you are looking for ways to visualize your cellular automaton there are several examples in the documentation. – C. E. Mar 11 '14 at 22:00
• Don't use MatrixForm; it is only intended for formatting output. CellularAutomaton wants a list for its 2nd argument (i.e., an expression with head List), not an expression with head MatrixForm, which is what you are giving it. Table returns a list that can be used without further processing. – m_goldberg Mar 12 '14 at 0:58

Please read Documentation HERE - especially Details section and all the examples.

• Not enough specification: is it general, totalistic or outer totalistic rule CA?
• What is the rule?
• By 4 neighbors you mean Von Neumann neighborhood?
• 100 colors are too many - hard to find interesting rules. Perhaps you want continuos color CA?

Well, assuming Von Neumann neighborhood, totalistic, 5 color CA you have (change 5 to 100 if you want but it will be boring):

Single non-zero cell initial condition:

dat = CellularAutomaton[
{173452345235, {5, {{0, 1, 0}, {1, 1, 1}, {0, 1, 0}}}, {1, 1}},
SparseArray[{{11, 11} -> 3}, {20, 20}], 13];

Image3D[Rescale@dat, ColorFunction -> "RainbowOpacity"]


Random initial condition:

dat = CellularAutomaton[
{14524645253, {5, {{0, 1, 0}, {1, 1, 1}, {0, 1, 0}}}, {1, 1}},
RandomInteger[4, {20, 20}], 20];

Image3D[Rescale@dat, ColorFunction -> "RainbowOpacity"]


Is this what you want?

MatrixPlot /@ CellularAutomaton[{100 (4 (100 - 1) + 1), {100, 1}, {1, 1}},
Table[RandomInteger[], {20}, {20}], 1]