A modern web-based aquarium simulator conceptually based on the 1993 aquarium simulator El-Fish. This browser-based implementation features procedurally generated fish with genetic algorithms controlling their appearance and behavior. Users can catch, breed, and evolve unique fish through selection and mutation, creating infinite variations from 56+ genetic traits. The simulator includes a fully customizable 3D aquarium environment with decorations, plants, and various backgrounds, all rendered in pure HTML5/CSS3/JavaScript without external dependencies. Fish genetics determine everything from body shape and fin types to colors, patterns, and swimming behaviors, making each fish truly unique.
The simulator implements a sophisticated genetic algorithm at its
heart, built around the FishGenome
class. Each fish carries
a genome containing over 56 distinct genes that control various
phenotypic expressions:
bodyLength
, bodyHeight
,
bodyWidth
: Control the elliptical body proportionsbodyTaper
: Determines how the body narrows toward the
taildorsalFinSize
, caudalFinSize
,
pectoralFinSize
, analFinSize
: Individual fin
dimensionsdorsalFinShape
(0-2): Round, pointed, or split dorsal
finscaudalFinShape
(0-3): Round, forked, fan, or veil tail
shapesscale
: Overall size multiplier (0.5x to 2x)hasGradient
: Boolean for gradient coloringgradientIntensity
: Strength of color transitionshasShimmer
: Rare iridescent effect genestripeCount
, stripeWidth
,
stripeAngle
: Vertical banding patternsspotCount
, spotSize
: Circular
markingspatternComplexity
: Triggers scale patterns at high
values (>0.7)speed
: Base swimming velocity (0.5-2.5 units)schooling
: Boolean for flocking behaviorverticalPreference
: Preferred depth in tank (0=bottom,
1=top)curiosity
: Food-seeking aggression multipliertailWagSpeed
: Frequency of tail oscillationfinWaveAmplitude
: Pectoral fin movement rangeThe mutation system uses Gaussian noise with configurable rates:
// Standard mutation adds ±30% noise
= oldValue + (Math.random() - 0.5) * 0.3 newValue
Special handling ensures valid ranges: - Hue values wrap at 360° - Counts floor to integers - All percentages clamp to [0,1]
Sexual reproduction implements: 1. Random inheritance: Each gene has 50% chance from either parent 2. Gene averaging: 20% chance of averaging continuous traits 3. Mutation on birth: Offspring receive 10% mutation rate
Each fish is dynamically rendered as an SVG with: 1.
Procedural body construction: Multiple ellipses create
body segments 2. Fin path generation: Bézier curves and
polygons based on fin genes 3. Pattern layering:
Stripes, spots, and scales added as SVG elements 4. Gradient
definitions: Dynamic <linearGradient>
and
<radialGradient>
elements
@keyframes
with dynamic durationrequestAnimationFrame
vx
and vy
with acceleration// Core movement loop (simplified)
1. Apply food attraction vectors if food present
2. Add random walk: vx += (Math.random() - 0.5) * 0.1
3. Apply vertical preference force
4. Implement schooling alignment with nearby fish
5. Clamp to maximum speed
6. Update position: x += vx * deltaTime
7. Handle boundary collisions
Fish with schooling=true
genes: 1. Detect neighbors
within 100px radius 2. Calculate average velocity vector of school 3.
Adjust own velocity 5% toward group average 4. Creates emergent flocking
patterns
{fishes: [{
genome: { genes: {...}, id: "fish_timestamp_random" },
name: "Generatedname"
,
}]generation: number,
background: string,
sandVisible: boolean,
decorations: [{
type: string,
left: string,
bottom: string
}] }
setInterval
localStorage
: Persistence (4MB typical limit)requestAnimationFrame
: Smooth animationCSS Custom Properties
: Dynamic stylingSVG 1.1
: Fish renderingES6 Classes
: Object-oriented structuregetBoundingClientRect()
Date.now()
for wide supportThe architecture supports easy additions:
FishGenome
constructorgenerateComplexPatterns()
update()
methodCurrently a single monolithic HTML file (~2000 lines) containing: - CSS styles (300 lines) - JavaScript classes and logic (1600 lines) - HTML structure (100 lines)
Potential refactoring into modules: - genetics.js
:
Genome and genetic operations - fish.js
: Fish class and
rendering - aquarium.js
: Environment management -
ui.js
: Interface and controls - storage.js
:
Persistence layer - styles.css
: Separated styles -
index.html
: Minimal HTML shell