// Button // by REAS // Click on one of the colored squares in the // center of the image to change the color of // the outside rectangle // Updated 09 February 2003 // Created 21 August 2002 int rectX, rectY; // Position of square button int circleX, circleY; // Position of circle button int rectSize = 50; // Diameter of rect int circleSize = 53; // Diameter of circle color rectColor, circleColor, baseColor; color rectHighlight, circleHighlight; color currentColor; boolean rectOver = false; boolean circleOver = false; int sx, sy; int[][][] world; void setup() { size(200, 200); sx = width; sy = height; world = new int[sx][sy][2]; background(0); setup2(); //currentColor = baseColor; //circleX = width/2+circleSize/2+10; //circleY = height/2; //rectX = width/2-rectSize-10; //rectY = height/2-rectSize/2; //ellipseMode(CENTER_DIAMETER); } void loop() { //update(mouseX, mouseY); loop3(); //background(currentColor); } void mousePressed() { currentColor = color(255,(int)random(255),255); setup2(); loop3(); } void setup2() { // initilize screen 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 loop3() { // 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]; stroke(255); if (current == 2) { //stroke(255,0,0); stroke(255); world[x][y][0] = 2; if (current==old) { //stroke(255,0,0); stroke(204); } } if (current == 3) { //stroke(0,255,0); stroke(153); world[x][y][0] = 3; if (current==old) { //stroke(0,255,0); stroke(102); } } if (current == 5){ //stroke(0,0,255); stroke(51); world[x][y][0] = 5; if (current==old) { //stroke(0,0,255); stroke(0); } } point(x, y); 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!=18){ if ((reds