Some kind of game of life!
in
Programming Questions
•
2 years ago
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.
-
int y;
-
int rule=129;
-
void setup()
-
{
-
size(256,256,P3D);
-
background(0);
-
set(width/2,0,~0);
-
}
-
void draw()
-
{
-
for(int x=1; x<width-1; x++)
-
{
-
int pix1= (get(x-1,y)&1)<<2;
-
int pix2= (get(x,y)&1)<<1;
-
int pix3= get(x+1,y)&1;
-
int bits=pix1+pix2+pix3;
-
if((rule&(1<<(bits)))>0) //test pattern in rule
-
set(x,y+1,~0);
-
}
-
if(++y>height)
-
exit();
-
}
1