// CSC152 // Implementation of a cellular automaton with a simple neighborhood rule: // if either left or right neighbor is turned on, turn on the cell in the // next generation. This can be represented graphically as follows (1 stands // for a cell that's on, 0 for off): // current generation: 101 100 001 111 110 011 // next generation: 1 1 1 1 1 1 // Notice that the above can be represented with a single conditional // statement public class CAsimple { 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 rule if (b.isOn(x-1, y) || b.isOn(x+1, y)) b.turnOn(x, y+1); // turn on cell in next generation (in the next row) } b.pause(50); //pause after every row } } }