xxxxxxxxxx
42
//See...
//cell.js for Cell class;
//background.txt for background on this program;
//TODO.txt for features yet to be implemented.
let cells = [];
let fr = 24; //frame rate (frames per second)
function setup() {
createCanvas(400, 400);
frameRate(fr);
//create initial population
for (i = 0; i < 10; i++) {
cells.push(new Cell(random(width), random(height), 3, random(0,3)));
}
}
function draw() {
background(220);
let daughters; //daughter cells
let pop = cells.length; //population size
//CELLS
//array is looped through backwards to avoid
//complications from modifying the array within the loop
for (let i = cells.length - 1; i >= 0; i--) {
cells[i].show();
cells[i].updateAge(fr);
if (cells[i].age > 2) {
daughters = cells[i].split();
cells.splice(i, 1); //remove mother cell
cells.push(daughters[0], daughters[1]);
}
}
//TITLE
textSize(24);
fill(0);
text("Population Size: " + pop, 10, height - 10);
}