// Glider class Glider { private int x; private int y; private int dnaLength; private int[] dna; private int noCells; private Cell[] cells; private color gliderColor; private boolean bidirectional; public Glider(int x, int y, color gliderColor, int dnaLength, int noCells, boolean bidirectional) { this.x = x; this.y = y; this.dnaLength = dnaLength; this.bidirectional = bidirectional; makeDna(); this.noCells = noCells; makeCells(); this.gliderColor = gliderColor; } private void makeDna() { dna = new int[dnaLength]; if (bidirectional) makeDnaBidirectional(); else makeDnaRandom(); } private void makeDnaRandom() { for (int i = 0; i < dnaLength; i++) dna[i] = int(random(8)); } private void makeDnaBidirectional() { int m = int(random(dnaLength)); int d1 = int(random(8)); int d2 = int(random(8)); for (int i = 0; i < dnaLength; i++) if (i < m) dna[i] = d1; else dna[i] = d2; } private void makeCells() { cells = new Cell[noCells]; for (int i = 0; i < noCells; i++) { cells[i] = new Cell(x, y, 0); for (int j = 0; j < i; j++) cells[j].update(dna[cells[j].getDnaPointer()], dnaLength); } } public void draw() { fill(gliderColor); for (int i = 0; i < noCells; i++) rect(xOffset + cells[i].getX() * gridSize, yOffset + cells[i].getY() * gridSize, gridSize, gridSize); } public void update() { for (int i = 0; i < noCells; i++) cells[i].update(dna[cells[i].getDnaPointer()], dnaLength); } }