So, I am trying to recreate the game of life in p5js. And for some reason, the official p5js web editor raises some sort of error in my code, which I have inspected thoroughly:
const segmentSize = 25;
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
class Organism {
constructor(column, row) {
this.column = column;
this.row = row;
this.status = true;
this.neighbours = [
[ , , ],
[ , , ],
[ , , ]
];
for (let i = -0; i < 2; i += 1) {
for (let j = 0; j < 2; j += 1) {
this.neighbours[column + i][row + j] = Point(column + i, row + j);
}
}
}
deactivate() {
this.status = false;
fill(0);
quad(
this.column - segmentSize, this.row - segmentSize,
this.column , this.row - segmentSize,
this.column , this.row ,
this.column - segmentSize, this.row
);
}
}
function grid() {
for (let i = segmentSize; i < width + segmentSize; i += segmentSize) {
for (let j = segmentSize; j < height + segmentSize; j+= segmentSize) {
quad(
i - segmentSize, j - segmentSize,
i , j - segmentSize,
i , j ,
i - segmentSize, j
);
}
}
}
function setup() {
createCanvas(500, 500);
background(0);
stroke(200, 255, 255);
strokeWeight(2);
}
function draw() {
grid();
}
The error seems to show up on lines 18, 19, and 20.The error says that “Empty array elements require elision=true”. I cannot make any sense of this, and there seems to be no friendly p5js error associated with it. I would really appreciate it if somebody would care to tell me what I am doing wrong.
In Conway’s Game of Life, each cell, with the possible exception of ones at the edges of the board, has eight neighboring cells. See Wikipedia: Conway’s Game of Life.
Following is quote from that page:
Every cell interacts with its eight neighbours , which are the cells that are horizontally, vertically, or diagonally adjacent.