xxxxxxxxxx
43
class Cell {
constructor(state, x, y, w) {
// What is the cell’s state?
this.state = state;
this.previous = this.state;
// position and size
this.x = x;
this.y = y;
this.w = w;
this.colors_1 = ["9e0031","8e0045","770058","600047","44001a"];
this.colors_2 = ["3c1518","69140e","a44200","d58936","f2f3ae"]
}
show() {
//stroke(0);
noStroke()
// If the cell is born, color it magenta
if (this.previous === 0 && this.state == 1) {
let randomColor = this.colors_1[
Math.floor(Math.random() * this.colors_1.length)];
fill(color('#' + randomColor));
//print(randomColor)
} else if (this.state == 1) {
fill(0);
// If the cell dies, color it from second palette!
} else if (this.previous == 1 && this.state === 0) {
let randomColor = this.colors_2[
Math.floor(Math.random() * this.colors_2.length)];
fill(color('#' + randomColor));
//print(randomColor)
} else {
fill(255);
}
//square(this.x, this.y, this.w);
ellipse(this.x, this.y, this.w);
}
}