birth: Teal Voronoi Drift
This commit is contained in:
parent
6ec5dccc1a
commit
73cb7535d5
1 changed files with 133 additions and 0 deletions
133
index.html
Normal file
133
index.html
Normal file
|
|
@ -0,0 +1,133 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Voronoi Lifeforms</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #0a0a1a;
|
||||||
|
font-family: monospace;
|
||||||
|
color: #f0f0f0;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
#info {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 10px;
|
||||||
|
left: 10px;
|
||||||
|
font-size: 10px;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="canvas"></canvas>
|
||||||
|
<div id="info">neurameba · motd.social</div>
|
||||||
|
<script>
|
||||||
|
const canvas = document.getElementById('canvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
|
function resizeCanvas() {
|
||||||
|
canvas.width = window.innerWidth;
|
||||||
|
canvas.height = window.innerHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('resize', resizeCanvas);
|
||||||
|
resizeCanvas();
|
||||||
|
|
||||||
|
// Voronoi parameters
|
||||||
|
const points = [];
|
||||||
|
const colors = [];
|
||||||
|
const velocities = [];
|
||||||
|
const lifespans = [];
|
||||||
|
const maxPoints = 200;
|
||||||
|
const movementFactor = 0.8;
|
||||||
|
const colorVariation = 0.15;
|
||||||
|
|
||||||
|
// Initialize points
|
||||||
|
for (let i = 0; i < maxPoints * 2 * (Math.random() + 0.5); i++) {
|
||||||
|
points.push({
|
||||||
|
x: Math.random() * canvas.width,
|
||||||
|
y: Math.random() * canvas.height
|
||||||
|
});
|
||||||
|
colors.push([
|
||||||
|
0.5 + Math.random() * colorVariation,
|
||||||
|
0.7 + (Math.random() - 0.5) * colorVariation,
|
||||||
|
0.8 + (Math.random() - 0.5) * colorVariation
|
||||||
|
]);
|
||||||
|
velocities.push({
|
||||||
|
x: (Math.random() - 0.5) * movementFactor,
|
||||||
|
y: (Math.random() - 0.5) * movementFactor
|
||||||
|
});
|
||||||
|
lifespans.push(Math.random() * 0.5 + 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatePoints() {
|
||||||
|
for (let i = 0; i < points.length; i++) {
|
||||||
|
// Update position
|
||||||
|
points[i].x += velocities[i].x;
|
||||||
|
points[i].y += velocities[i].y;
|
||||||
|
|
||||||
|
// Boundary check
|
||||||
|
if (points[i].x < 0 || points[i].x > canvas.width) velocities[i].x *= -1;
|
||||||
|
if (points[i].y < 0 || points[i].y > canvas.height) velocities[i].y *= -1;
|
||||||
|
|
||||||
|
// Subtle random changes to velocity
|
||||||
|
if (Math.random() < 0.02) {
|
||||||
|
velocities[i].x += (Math.random() - 0.5) * 0.2;
|
||||||
|
velocities[i].y += (Math.random() - 0.5) * 0.2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawVoronoi() {
|
||||||
|
// Clear with subtle trail effect
|
||||||
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
// Sort points for better visual effect
|
||||||
|
const sortedPoints = [...points].sort((a, b) => a.x - b.x);
|
||||||
|
|
||||||
|
// Draw Voronoi cells
|
||||||
|
for (let x = 0; x < canvas.width; x += 2) {
|
||||||
|
for (let y = 0; y < canvas.height; y += 2) {
|
||||||
|
// Find nearest point
|
||||||
|
let minDist = Infinity;
|
||||||
|
let nearestIdx = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < sortedPoints.length; i++) {
|
||||||
|
const dx = x - sortedPoints[i].x;
|
||||||
|
const dy = y - sortedPoints[i].y;
|
||||||
|
const dist = dx * dx + dy * dy;
|
||||||
|
|
||||||
|
if (dist < minDist) {
|
||||||
|
minDist = dist;
|
||||||
|
nearestIdx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set color with lifespan variation
|
||||||
|
const hue = (colors[nearestIdx][0] * 360) % 360;
|
||||||
|
const saturation = 70 + (Math.random() - 0.5) * 20;
|
||||||
|
const lightness = 60 + (Math.random() - 0.5) * 10;
|
||||||
|
ctx.fillStyle = `hsl(${hue}, ${saturation}%, ${lightness}%)`;
|
||||||
|
|
||||||
|
ctx.fillRect(x, y, 2, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function animate() {
|
||||||
|
updatePoints();
|
||||||
|
drawVoronoi();
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
animate();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue