Loading...
Logo
Processing Forum

How could we write a program of three-color totalistic one-dimensional Cellular Automata (CA).

It is like the game of life program.

I know how to write two-color one-dimensional.

It is really funny, and changing the rules make pretty pattern.

Is there anyone to have any idea how to do this?

I put the code of two-color one-dimensional below.

Any idea will help.

Copy code
  1. int y;
  2. int rule=129;
  3. void setup()
  4. {
  5.   size(256,256,P3D);
  6.   background(0);
  7.   set(width/2,0,~0);
  8. }
  9. void draw()
  10. {
  11.   for(int x=1; x<width-1; x++)
  12.   {
  13.     int pix1= (get(x-1,y)&1)<<2;
  14.     int pix2= (get(x,y)&1)<<1;
  15.     int pix3=  get(x+1,y)&1;
  16.     int bits=pix1+pix2+pix3;
  17.     if((rule&(1<<(bits)))>0)    //test pattern in rule
  18.       set(x,y+1,~0);
  19.   }
  20.   if(++y>height)
  21.   exit();
  22. }

Replies(2)

I cannot answer to your question because I cannot read your message: it is displayed (with Firefox) as 7 pixel high font!
Please, try and use a better font.

And if you ask a question, don't change the topic type to discussion, leave it to "Question". Thanks.
I wish you can read my message with this font.
 
How could we write a program of three-color totalistic one-dimensional Cellular Automata (CA).

It is like the game of life program.

I know how to write two-color one-dimensional.

It is really funny, and changing the rules make pretty pattern.

Is there anyone to have any idea how to do this?

I put the code of two-color one-dimensional below.

Any idea will help.

Copy code

  1. int y;

  2. int rule=129;

  3. void setup()

  4. {

  5.   size(256,256,P3D);

  6.   background(0);

  7.   set(width/2,0,~0);

  8. }

  9. void draw()

  10. {

  11.   for(int x=1; x<width-1; x++)

  12.   {

  13.     int pix1= (get(x-1,y)&1)<<2;

  14.     int pix2= (get(x,y)&1)<<1;

  15.     int pix3=  get(x+1,y)&1;

  16.     int bits=pix1+pix2+pix3;

  17.     if((rule&(1<<(bits)))>0)    //test pattern in rule

  18.       set(x,y+1,~0);

  19.   }

  20.   if(++y>height)

  21.   exit();

  22. }