Creation vs Evolution: Watch both unfold and thrive in realtime.
Creation Theory:
I conducted a personal investigation comparing creation theory and evolution by running simulations designed by me. While I don't claim to be an expert scientist, I believe the data I gathered is reasonably reliable. Initially, both theories seemed plausible, prompting me to contemplate the best approach for simulation. I pondered whether to utilize a game engine, leverage my newfound skills in Java, or apply my years of experience with Python. After careful consideration, I opted for JavaScript and HTML, acknowledging the complexity of the decision-making process.
I dedicated significant time and effort to envisioning the simulation's appearance, recognizing the importance of conveying my point in a somewhat decent manner. My initial approach involved creating dots of various colors, without delving too deeply into other aspects, given my lack of prior experience with JavaScript. In navigating this unfamiliar territory, Google became my go-to companion.
I established a canvas, introduced dots, and included plants for the herbivores. As the canvas became animated with dots, I decided it was time to enhance their dynamics. I incorporated code that allowed the dots to move randomly along the X and Y axes, injecting a degree of unpredictability into their navigation for a more engaging simulation.
I observed the dots constantly wandering off the canvas, so I had to confine them to it and establish a food chain. Additionally, I introduced a breeding mechanism. The end result is a finalized simulation that incorporates these adjustments.
Creation Theory: Final product
Code:
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const BLACK = '#000';
const GREEN = '#00FF00';
const YELLOW = '#FFFF00';
const BROWN = '#8B4513';
const RED = '#FF0000';
const ORANGE = '#FFA500';
const BLUE = '#0000FF';
const PURPLE = '#800080';
const organisms = [];
const maxOrganisms = 100;
class Organism {
constructor(x, y, type, foodChainLevel, isHuman) {
this.x = x;
this.y = y;
this.type = type;
this.foodChainLevel = foodChainLevel;
this.isHuman = isHuman;
this.setColor();
this.lastMultiplyTime = 100;
this.multiplyCooldown = 25000; // 25 seconds cooldown in milliseconds
}
setColor() {
if (this.isHuman) {
this.color = BLUE;
} else {
switch (this.type) {
case 'plant':
this.color = GREEN;
break;
case 'herbivore':
this.color = (this.foodChainLevel === 1) ? YELLOW : BROWN;
break;
case 'carnivore':
this.color = (this.foodChainLevel === 2) ? RED : ORANGE;
break;
case 'carnivorous plant':
this.color = PURPLE;
break;
default:
this.color = BLACK;
break;
}
}
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, 5, 0, 2 * Math.PI);
ctx.fillStyle = this.color;
ctx.fill();
ctx.stroke();
// Draw name above organism
ctx.fillStyle = BLACK;
ctx.font = '12px sans-serif';
ctx.fillText(this.type, this.x - 20, this.y - 20);
}
move() {
if (this.isHuman || this.type === 'herbivore' || this.type === 'carnivore') {
this.x += Math.random() * 4 - 2;
this.y += Math.random() * 4 - 2;
this.x = Math.max(5, Math.min(canvas.width - 5, this.x));
this.y = Math.max(5, Math.min(canvas.height - 5, this.y));
this.interact();
}
}
interact() {
const currentTime = Date.now();
if (currentTime - this.lastMultiplyTime > this.multiplyCooldown) {
for (const otherOrganism of organisms) {
if (otherOrganism !== this && this.isTouching(otherOrganism)) {
this.handleInteraction(otherOrganism);
this.lastMultiplyTime = currentTime; // Update last multiply time
}
}
}
}
isTouching(otherOrganism) {
const distance = Math.sqrt((this.x - otherOrganism.x)**2 + (this.y - otherOrganism.y)**2);
return distance < 10;
}
handleInteraction(otherOrganism) {
const randomChance = Math.random();
if (this.type === 'carnivore' && otherOrganism.type === 'herbivore' && randomChance < 0.4) {
organisms.splice(organisms.indexOf(otherOrganism), 1);
} else if (this.type === 'human' && otherOrganism.type === 'human' && randomChance < 0.24) {
organisms.splice(organisms.indexOf(otherOrganism), 1);
} else if (this.type === 'herbivore' && otherOrganism.type === 'carnivore' && randomChance < 0.15) {
organisms.splice(organisms.indexOf(otherOrganism), 1);
} else if (this.type === 'human' && (otherOrganism.type !== 'human' && otherOrganism.type !== 'plant') && randomChance < 0.4) {
organisms.splice(organisms.indexOf(otherOrganism), 1);
} else if (this.type === 'plant' && Math.random() < 0.1 && organisms.length < maxOrganisms) {
const newPlant = new Organism(Math.random() * (canvas.width - 10) + 5, Math.random() * (canvas.height - 10) + 5, 'plant', 0, false);
organisms.push(newPlant);
}
}
}
function createInitialOrganisms() {
for (let i = 0; i < 30; i++) {
const x = Math.random() * (canvas.width - 10) + 5;
const y = Math.random() * (canvas.height - 10) + 5;
organisms.push(new Organism(x, y, 'plant', 0, false));
}
for (let i = 0; i < 30; i++) {
const x = Math.random() * (canvas.width - 10) + 5;
const y = Math.random() * (canvas.height - 10) + 5;
organisms.push(new Organism(x, y, 'herbivore', 1, false));
}
for (let i = 0; i < 20; i++) {
const x = Math.random() * (canvas.width - 10) + 5;
const y = Math.random() * (canvas.height - 10) + 5;
organisms.push(new Organism(x, y, 'carnivore', 2, false));
}
for (let i = 0; i < 10; i++) {
const x = Math.random() * (canvas.width - 10) + 5;
const y = Math.random() * (canvas.height - 10) + 5;
organisms.push(new Organism(x, y, 'human', 3, true));
}
}
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (const organism of organisms) {
organism.move();
organism.draw();
}
requestAnimationFrame(draw);
}
createInitialOrganisms();
draw();
Evolution Theory:
Transitioning to the realm of evolution, it's quite a complex journey. To kick things off, we'll take a patient approach and wait for a million years or so, observing in real-time how everything unfolds and plays out.
Code: