int sx, sy; float density = 0.5; int[][][] world; void setup() { size(200, 200); framerate(12); sx = width/10; sy = height/10; world = new int[sx][sy][2]; background(0); //noStroke(); // Set random cells to 'on' for (int i = 0; i < (sx * sy); i++) { int aaa=(int)random(3); if (aaa==0){world[i%(sx)][(i/sy)][1] =2;} if (aaa==1){world[i%(sx)][(i/sy)][1] =3;} if (aaa>1){world[i%(sx)][(i/sy)][1] =5;} } } void loop() { // Drawing and update cycle for (int x = 0; x < sx; x=x+1) { for (int y = 0; y < sy; y=y+1) { //world[x][y][0] = world[x][y][1]; int current=world[x][y][1]; int old=world[x][y][0]; fill(0); if (current == 2) { //stroke(255,0,0); fill(255,0,0); world[x][y][0] = 2; if (current==old) { //stroke(255,0,0); //fill(204); } } if (current == 3) { fill(0,255,0); //fill(0,153,); world[x][y][0] = 3; if (current==old) { //stroke(0,255,0); //fill(102); } } if (current == 5){ fill(0,0,255); //fill(51); world[x][y][0] = 5; if (current==old) { //stroke(0,0,255); //fill(0); } } rect(x*10,y*10,(x*10)+10,(y*10)+10); world[x][y][1] = 0; } } // Birth and death cycle for (int x = 1; x < sx-1; x=x+1) { for (int y = 1; y < sy-1; y=y+1) { int count = check_hood(x, y); if (count == 2 ){world[x][y][1] = 2; } if (count == 3 ){world[x][y][1] = 3; } if (count == 5 ){world[x][y][1] = 5; } // if ((count < 2 || count > 3) && world[x][y][0] == 1) // { //world[x][y][0] = 0; //} } } } int check_hood(int x,int y){ byte reds,greens,blues,minority; double total,product; reds=0; greens=0; blues=0; total=neighbors(x,y) ; while (total%2==0){ total=total/2; reds++; } while (total%3==0){ total=total/3; greens++; } while (total%5==0){ total=total/5; blues++; } product=blues*reds*greens; minority=(byte)world[x][y][0]; //if (product==0){ if ((reds