// CSC152 // Implementation of a cellular automaton with neighborhood rule 30: // This can be represented graphically as follows (1 stands for a cell // that's on, 0 for off): // current generation: 100 011 010 001 // next generation: 1 1 1 1 public class CA30 { public static void main(String[] args) { int cols = 200, rows = 100; Board b = new Board(cols, rows); b.turnOn(cols/2, 0); // in generation 0, only middle cell is on for (int y = 0; y < rows-1; y++) { // first and last column don't have a left and right neightbor respectively, // so start with the second column and stop at the second to last column for (int x = 1; x < cols-1; x++) { // apply the rules: rule 100 if (b.isOn(x-1, y) && !b.isOn(x, y) && !b.isOn(x+1, y)) b.turnOn(x, y+1); // rule 011 else if (!b.isOn(x-1, y) && b.isOn(x, y) && b.isOn(x+1, y)) b.turnOn(x, y+1); // rule 010 else if (!b.isOn(x-1, y) && b.isOn(x, y) && !b.isOn(x+1, y)) b.turnOn(x, y+1); // rule 001 else if (!b.isOn(x-1, y) && !b.isOn(x, y) && b.isOn(x+1, y)) b.turnOn(x, y+1); } b.pause(50); //pause after every row } } }