1

I need to create a new CA RULE in Mathematica. How can I do? I mean, I need to create a CA with 3 colors (Black, White and Grey). May you help me?

1 Answers1

3

One way to specify a custom rule is to define a function which, given a list of neighbours and time step, will output the updated value. For example

fun[lst_, t_] := Mod[Total[lst], 3]

which will simply calculate the sum of all neighbours of an element modulo 3. This function can then be used in CellularAutomaton as follows

With[{init = {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, nsteps = 10, r = 1},
   res = CellularAutomaton[{fun, {}, r}, init, nsteps]]

ArrayPlot[res]

Mathematica graphics

Heike
  • 24,102
  • 2
  • 31
  • 45
  • Many Thanks. For Example, If I want to have the following output using three colors: {0,1,1,0,2,2,1,0}, may I set a function starting from it? – Daniele Ricci Jul 04 '12 at 13:09
  • @DanieleRicci What exactly do you mean? The arguments provided to `fun` in my example above are the neighbourhood of a cell and the timestep, so for a 1D CA with a neighbourhood radius of 1 and possible states 0, 1, 2, you would need to specify `fun[{0, 0, 0}, t]`, `fun[{0, 0, 1}, t]`, ... , and `fun[{2, 2, 2}, t]` where `t` is the time step. – Heike Jul 04 '12 at 13:38
  • Dear Heike, I mean sorry for my stupid questions: I want to havet the following rule: white (0), black (1), Grey (2) --> 0, 0, 0 --> 0; 0,0,1--> – Daniele Ricci Jul 04 '12 at 13:57