xxxxxxxxxx
87
let cells = [];
let randomCell;
let timer;
let numOfStartingCells;
let mitosisCounter;
let combineCounter;
let cellCounter;
let informationDiv;
function setup() {
createCanvas(windowWidth, 720);
numOfStartingCells = floor(width/15);
for (let i = 0; i < numOfStartingCells; i++) {
cells[i] = new Cell();
}
setInterval(Mitosis, 2000);
mitosisCounter = 0;
combineCounter = 0;
cellCounter = 0;
informationDiv = createDiv();
}
function draw() {
background(0);
for (let i = cells.length - 1; i >= 0; i--) {
let combined = false;
cells[i].move();
cells[i].show();
for (let j = cells.length - 1; j >= 0; j--) {
let d = dist(cells[i].pos.x, cells[i].pos.y, cells[j].pos.x, cells[j].pos.y);
if (d < (cells[i].r + cells[j].r) * 0.5 && cells[i].c != cells[j].c) {
Combine(cells[i], cells[j]);
cells.splice(j, 1);
combined = true;
combineCounter++;
}
}
if (combined) {
cells.splice(i, 1);
combined = false;
}
}
cellCounter = cells.length - 1;
informationDiv.html("Starting Cells: " + numOfStartingCells + " / Total Cells: " + cellCounter + " / Mitosis: " + mitosisCounter + " / Combinations: " + combineCounter);
}
function Combine(cellA, cellB) {
let newCell = new Cell(cellA.pos, (cellA.r + cellB.r) * 0.6, color(random(255), random(255), random(255)));
cells.push(newCell);
}
function Mitosis() {
randomCell = floor(random(cells.length - 1));
//console.log(randomCell);
for (let i = cells.length - 1; i >= 0; i--) {
if (cells[i].r > 10) {
if (random(1) < 0.45) {
cells.push(cells[i].mitosis());
cells[i].r = cells[i].r * 0.8;
mitosisCounter++;
}
}
}
}
function mousePressed() {
for (let i = cells.length - 1; i >= 0; i--) {
if (cells[i].clicked(mouseX, mouseY)) {
cells.push(cells[i].mitosis());
cells.push(cells[i].mitosis());
cells.splice(i, 1);
console.log("Clicked")
}
}
}
function mouseDragged() {
for (let i = cells.length - 1; i >= 0; i--) {
if (cells[i].clicked(mouseX, mouseY)) {
cells[i].pos.x = mouseX;
cells[i].pos.y = mouseY;
}
}
}