cellular automaton 30
in
Programming Questions
•
2 years ago
I copied the following code from the a book. It is the code for the cellular automaton 30. What I want this script to do is to print my automaton like it would normally do but when it reaches the line 30, to leave it blank. I do this by deleting the line 30 when the automaton reaches the 31st line. Any other hint how to do this on the go by temporarily keeping the values of the line 30 but not displaying them?thx
int[] rules = {0,0,0,1,1,1,1,0};
int gen = 1; // Generation
color on = color(255);
color off = color(0);
void setup() {
size(301,301);
frameRate(91);
background(0);
set(width/2,0,on);
}
void draw(){
for (int i=1;i<width-1;i++) {
int left = get(i-1, gen-1);
int center = get(i,gen-1);
int right = get(i+1, gen-1);
if (rules(left,center,right) == 1) {
set(i,gen,on);
if (gen==31){
set(i,30,off);
}
}
}
gen++;
if (gen > height-1){
noLoop();}
}
int rules(color a,color b,color c) {
if ((a == on) && (b == on) && (c==on)) {return 0;}
if ((a == on) && (b == on) && (c==off)) {return 0;}
if ((a == on) && (b == off) && (c==on)) {return 0;}
if ((a == on) && (b == off) && (c==off)) {return 1;}
if ((a == off) && (b == on) && (c==on)) {return 1;}
if ((a == off) && (b == on) && (c==off)) {return 1;}
if ((a == off) && (b == off) && (c==on)) {return 1;}
if ((a == off) && (b == off) && (c==off)) {return 0;}
return 0;
}
1