Prototype for evo
Displays basic spread and interactions of organisms with their environments
by CaelestisInteritum
HTML
<table id="displaySpeciesGrowth">
<tr>
<td id="cell0"></td>
<td id="cell1"></td>
<td id="cell2"></td>
<td id="cell3"></td>
</tr>
<tr>
<td id="cell4"></td>
<td id="cell5"></td>
<td id="cell6"></td>
<td id="cell7"></td>
</tr>
<tr>
<td id="cell8"></td>
<td id="cell9"></td>
<td id="cell10"></td>
<td id="cell11"></td>
</tr>
<tr>
<td id="cell12"></td>
<td id="cell13"></td>
<td id="cell14"></td>
<td id="cell15"></td>
</tr>
</table>
JavaScript
var map = [];
var pop = [];
var sourceBlock = random(0, 16);
var totalInstantiated = 0;
generate();
var updater = setInterval(function () {
update();
}, 1000);
function random(min, max) {
var rand = Math.random();
rand *= (max - min);
rand += min;
rand = Math.floor(rand);
return rand;
}
function tile() {
this.biome = random(0, 4);
this.temp = (this.biome - 2) * random(0, 10);
this.weather = random(0, 3);
this.food = random(10, 60);
}
function organism() {
this.number = 0;
this.temp = 0;
this.weather = 0;
this.food = 0;
this.growth = 0;
this.spread = 0;
this.instantiate = instantiatePop;
this.getStatus = getPopStatus;
}
function instantiatePop(parent, location) {
if (parent > -1) {
this.number = totalInstantiated + 1;
this.temp = pop[parent].temp;
this.weather = pop[parent].weather;
this.food = pop[parent].food;
this.growth = pop[parent].growth;
this.spread = Math.floor(pop[parent].spread / 2);
} else {
this.number = 1;
this.temp = map[location].biome * random(-5, 5);
this.weather = random(0, 3);
this.food = random(30, 60);
this.growth = 20;
this.spread = 50;
}
totalInstantiated++;
}
function getPopStatus() {
if (this.spread > 0) return [("Organism: " + this.number + "<br /><br />Growth Rate: " + this.growth + "<br /><br />Spread: " + this.spread), true];
else return ["<br /> <br /><br /><br /><br />", false];
}
function generate() {
for (var i = 0; i < 16; i++) {
map[i] = new tile();
pop[i] = new organism();
if (i == sourceBlock) pop[i].instantiate(-1, sourceBlock);
}
update();
}
function update() {
var cell;
var info;
var adjacent;
var...