Life Simulator

See it live here.

I am excited to share my latest project, the Life Simulator, a dynamic ecosystem simulation built using JavaScript and HTML. This project showcases a virtual world where different entities interact based on predefined behaviors and environmental factors. The source code is available on GitHub.

The Life Simulator creates a virtual ecosystem where various entities, such as trees, herbivores, and carnivores, coexist and interact. These interactions are governed by specific rules and behaviors that mimic natural processes like feeding, fleeing from predators, and procreating. The simulation runs in a HTML canvas, providing a visual representation of these interactions.

Entities and Behaviors

  • Trees: Act as the primary food source for herbivores. They have a static position and a slow energy gain over time.
  • Herbivores: Move around the environment seeking food (trees) and have the ability to procreate under certain conditions.
  • Carnivores: Hunt herbivores (and sometimes other carnivores) for sustenance. They also procreate and exhibit fleeing behavior when threatened.

Simulation Configuration

The simulation is configured with parameters that define the world’s size, population ranges for different entities, and various features such as energy bars and procreation animations. This configuration allows for easy adjustments to the simulation’s complexity and realism.

Dynamic Environment

Entities exhibit different behaviors based on their state and environmental stimuli:

  • Seek Food: Herbivores and carnivores search for food sources when their energy levels are low.
  • Fleeing: Herbivores attempt to escape when a predator is nearby.
  • Relax: Entities remain idle when they are neither hungry nor threatened.

Energy Management

Each entity has an energy level that influences its behavior:

  • Energy Gain and Consumption: Trees gain energy slowly, while herbivores and carnivores lose energy over time and gain it by consuming food.
  • Energy Bar: A visual representation of an entity’s energy level is displayed, with different colors indicating healthy or critical energy states.

Procreation and Survival

Entities can procreate if certain conditions are met, contributing to the dynamic nature of the ecosystem. The simulation includes animations to visually represent the act of procreation.


  • It is very hard to make the system stable, population wise.