Vichniac Vote
https://gyazo.com/91212e2666985d02e3847e8ccde1162c
code:java
Cell[][] _cellArray;
int _cellSize = 10;
int _numx, _numy;
void setup() {
size(500, 300);
_numx = floor(width/_cellSize);
_numy = floor(height/_cellSize);
restart();
}
void restart() {
_cellArray = new Cell_numx_numy;
for (int x = 0; x < _numx; x++) {
for (int y = 0; y < _numy; y++) {
Cell newCell = new Cell(x, y);
_cellArrayxy = newCell;
}
}
for (int x = 0; x < _numx; x++) {
for (int y = 0; y < _numy; y++) {
int above = y-1;
int below = y+1;
int left = x-1;
int right = x+1;
if (above < 0) { above = _numy-1; }
if (below == _numy) { below = 0; }
if (left < 0) { left = _numx-1; }
if (right == _numx) { right = 0; }
_cellArrayxy.addNeighbour(_cellArrayleftabove);
_cellArrayxy.addNeighbour(_cellArraylefty);
_cellArrayxy.addNeighbour(_cellArrayleftbelow);
_cellArrayxy.addNeighbour(_cellArrayxabove);
_cellArrayxy.addNeighbour(_cellArrayxbelow);
_cellArrayxy.addNeighbour(_cellArrayrightabove);
_cellArrayxy.addNeighbour(_cellArrayrighty);
_cellArrayxy.addNeighbour(_cellArrayrightbelow);
}
}
}
void draw() {
background(200);
for (int x = 0; x < _numx; x++) {
for (int y = 0; y < _numy; y++) {
_cellArrayxy.calcNextState();
}
}
translate(_cellSize/2, _cellSize/2);
for (int x = 0; x < _numx; x++) {
for (int y = 0; y < _numy; y++) {
_cellArrayxy.drawMe();
}
}
saveFrame("###.jpg");
}
void mousePressed() {
restart();
}
class Cell {
float x, y;
boolean state;
boolean nextState;
Cell[] neighbors;
Cell(float ex, float why) {
x = ex * _cellSize;
y = why * _cellSize;
if (random(2) > 1) {
nextState = true;
} else {
nextState = false;
}
state = nextState;
neighbors = new Cell0;
}
void addNeighbour(Cell cell) {
neighbors = (Cell[])append(neighbors, cell);
}
void calcNextState() {
int liveCount = 0;
if (state) {
liveCount++;
}
for (int i = 0; i < neighbors.length; i++) {
if (neighborsi.state == true) {
liveCount++;
}
}
if (liveCount <= 4) {
nextState = false;
} else if (liveCount > 4) {
nextState = true;
}
if ((liveCount == 4) || (liveCount == 5)) {
nextState = !nextState;
}
}
void drawMe() {
state = nextState;
stroke(0);
if (state == true) {
fill(0);
} else {
fill(255);
}
ellipse(x, y, _cellSize, _cellSize);
}
}
#processing #generativeart #mattpearson #gameoflife