Wikipedia links to information about Conway’s Game of Life, and Moore neighborhood
Conway’s Game of Life demands the following rules:
- Any live cell with fewer than two live neighbours dies, as if caused by under-population.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by over-population.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
See if you can find all the fan favorite characters such as; the all seeing eye, the plus sign blinker, and/or the Glider spaceship.
public static ArrayList RedXList = new ArrayList(); public static ArrayList RedYList = new ArrayList(); public static ArrayList BornXList = new ArrayList(); public static ArrayList BornYList = new ArrayList(); public static ArrayList underpopXList = new ArrayList(); public static ArrayList underpopYList = new ArrayList(); public static ArrayList overpopXList = new ArrayList(); public static ArrayList overpopYList = new ArrayList(); public static Boolean first = true; public static Boolean greencondition = false; public static Boolean greencondition2 = false; public static Boolean greencondition3 = false; public static Boolean greencondition4 = false; public static Boolean greencondition5 = false; public static color primary_color = #0066AA; public static int size = 6; public static int multiplyPrimary = 6; public static int secmulti = 3; public static int roundness = 2; void setup() { size(1480, 850); background(#000000); } void draw() { if (first) { InitialSoup(); first = false; greencondition = true; } else if ( greencondition ) { RedXList.clear(); RedYList.clear(); BornXList.clear(); BornYList.clear(); underpopXList.clear(); underpopYList.clear(); overpopXList.clear(); overpopYList.clear(); //SCAN// scan(); //Alive and stays alive for (int i = 0; i < RedXList.size(); i++) { int x = Integer.parseInt(RedXList.get(i).toString()); int y = Integer.parseInt(RedYList.get(i).toString()); fill( primary_color ); rect( x, y , size, size, roundness); } greencondition = false; greencondition2 = true; } else if ( greencondition2) { //Born with excessive neighbors for (int i = 0; i < BornXList.size(); i++) { int x = Integer.parseInt(BornXList.get(i).toString()); int y = Integer.parseInt(BornYList.get(i).toString()); fill( #cc0000); rect( x, y , size, size, roundness); } greencondition2 = false; greencondition3 = true; } else if (greencondition3 ) { //Under pop deaths for (int i = 0; i < underpopXList.size(); i++) { int x = Integer.parseInt(underpopXList.get(i).toString()); int y = Integer.parseInt(underpopYList.get(i).toString()); fill( #000000); rect( x, y , size, size, roundness); } greencondition3 = false; greencondition4 = true; } else if (greencondition4 ) { //Over pop deaths for (int i = 0; i < overpopXList.size(); i++) { int x = Integer.parseInt(overpopXList.get(i).toString()); int y = Integer.parseInt(overpopYList.get(i).toString()); fill( #000000); rect( x, y , size, size, roundness); } greencondition4 = false; greencondition5 = true; } else if ( greencondition5) { ///color all green again for (int i = 0; i < RedXList.size(); i++) { int x = Integer.parseInt(RedXList.get(i).toString()); int y = Integer.parseInt(RedYList.get(i).toString()); fill( primary_color); rect( x, y , size, size, roundness); } for (int i = 0; i < BornXList.size(); i++) { int x = Integer.parseInt(BornXList.get(i).toString()); int y = Integer.parseInt(BornYList.get(i).toString()); fill( primary_color); rect( x, y , size, size, roundness); } greencondition = true; } } void InitialSoup() { //INITIAL CELL SOUP paint// int r = int(random(0,7)); for ( int v = 10; v < 129; v++) { for ( int h = 10; h < 222; h++) { r = int(random(0,10)); if ( r == 0) fill(primary_color); else fill(#000000); rect( h*multiplyPrimary + size, v*multiplyPrimary , size, size, roundness); } } } void scan() { //SCAN// for ( int v = 10; v < 129; v++) { for ( int h = 11; h < 223; h++) { int x = h * multiplyPrimary; int y = v * multiplyPrimary; color c = get(x+secmulti, y+secmulti); int neighbor = 0; // E if ( get( (x+secmulti)+multiplyPrimary , (y+secmulti) ) == primary_color ) { neighbor+=1; } // W if ( get( (x+secmulti)-multiplyPrimary , (y+secmulti) ) == primary_color ) { neighbor+=1; } // N if ( get( (x+secmulti) , (y+secmulti) -multiplyPrimary ) == primary_color ) { neighbor+=1; } // S if ( get( (x+secmulti) , (y+secmulti) +multiplyPrimary ) == primary_color ) { neighbor+=1; } // NE if ( get( (x+secmulti) + multiplyPrimary , (y+secmulti) -multiplyPrimary ) == primary_color ) { neighbor+=1; } // SE if ( get( (x+secmulti) + multiplyPrimary , (y+secmulti) +multiplyPrimary ) ==primary_color ) { neighbor+=1; } // SW if ( get( (x+secmulti) - multiplyPrimary , (y+secmulti) +multiplyPrimary ) == primary_color) { neighbor+=1; } // NW if ( get( (x+secmulti) - multiplyPrimary , (y+secmulti) -multiplyPrimary ) == primary_color) { neighbor+=1; } if ( neighbor == 2 || neighbor == 3 ) { //store this if ( c == color(primary_color)) { RedXList.add(x); RedYList.add(y); } } if ( neighbor == 3 ) { //if ( c == -1 ) if ( c == color(#000000)) { BornXList.add(x); BornYList.add(y); } } if ( neighbor < 2 ) { if ( c == color(primary_color) ) { underpopXList.add(x); underpopYList.add(y); } } if ( neighbor > 3 ) { if ( c == color(primary_color)) { overpopXList.add(x); overpopYList.add(y); } } } } } |