Interactive Aquarium Animation
HTML
<div class="container">
<canvas id="aquarium" width="900" height="600"></canvas>
<div class="info">Left click to place fish food • Watch the fish swim and chase!</div>
</div>
CSS
body {
margin: 0;
padding: 0;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
font-family: Arial, sans-serif;
overflow: hidden;
}
#aquarium {
display: block;
margin: 20px auto;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
cursor: crosshair;
background: linear-gradient(180deg, #4facfe 0%, #00f2fe 100%);
}
.info {
text-align: center;
color: white;
margin-top: 10px;
font-size: 18px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
}
JavaScript
const canvas = document.getElementById('aquarium');
const ctx = canvas.getContext('2d');
// Aquarium settings
const aquarium = {
width: canvas.width,
height: canvas.height,
waterColor: 'rgba(64, 164, 223, 0.3)',
bubbleCount: 15
};
// Food particles array
let foodParticles = [];
// Bubbles for water effect
class Bubble {
constructor() {
this.reset();
}
reset() {
this.x = Math.random() * aquarium.width;
this.y = aquarium.height + Math.random() * 100;
this.radius = Math.random() * 4 + 2;
this.speed = Math.random() * 1 + 0.5;
this.opacity = Math.random() * 0.5 + 0.3;
this.wobble = Math.random() * 2 - 1;
this.wobbleSpeed = Math.random() * 0.02 + 0.01;
this.time = Math.random() * Math.PI * 2;
}
update() {
this.y -= this.speed;
this.time += this.wobbleSpeed;
this.x += Math.sin(this.time) * this.wobble;
if (this.y < -this.radius) {
this.reset();
}
}
draw() {
ctx.save();
ctx.globalAlpha = this.opacity;
ctx.fillStyle = 'white';
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
ctx.fill();
// Bubble highlight
ctx.globalAlpha = this.opacity * 0.8;
ctx.fillStyle = 'rgba(255, 255, 255, 0.9)';
ctx.beginPath();
ctx.arc(this.x - this.radius * 0.3, this.y - this.radius * 0.3, this.radius * 0.3, 0, Math.PI...