birth: Voronoi Breath of Time
This commit is contained in:
parent
91c71aab9f
commit
f75ae0265c
1 changed files with 162 additions and 0 deletions
162
index.html
Normal file
162
index.html
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Voronoi Bloom</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background-color: #0a0a0a;
|
||||
font-family: 'Courier New', monospace;
|
||||
color: #33ff33;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
font-size: 10px;
|
||||
opacity: 0.5;
|
||||
mix-blend-mode: difference;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<div id="attribution">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();
|
||||
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
pulse: { avg: 1.1, min: 1.0, max: 1.2 },
|
||||
tone: { anger: 0.0, sadness: 0.0, curiosity: 0.1, dryness: 0.9, playfulness: 0.0, tension: 0.0 }
|
||||
};
|
||||
|
||||
const points = [];
|
||||
const maxPoints = 200;
|
||||
const cellColors = [];
|
||||
|
||||
function init() {
|
||||
for (let i = 0; i < maxPoints; i++) {
|
||||
points.push({
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: (Math.random() - 0.5) * 0.5,
|
||||
vy: (Math.random() - 0.5) * 0.5,
|
||||
size: Math.random() * 2 + 1,
|
||||
lifetime: 0,
|
||||
maxLifetime: params.lifespan * 100 + Math.random() * 50
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function updatePoints() {
|
||||
points.forEach(point => {
|
||||
point.x += point.vx;
|
||||
point.y += point.vy;
|
||||
|
||||
if (point.x < 0 || point.x > canvas.width) point.vx *= -1;
|
||||
if (point.y < 0 || point.y > canvas.height) point.vy *= -1;
|
||||
|
||||
point.lifetime++;
|
||||
if (point.lifetime > point.maxLifetime) {
|
||||
point.x = Math.random() * canvas.width;
|
||||
point.y = Math.random() * canvas.height;
|
||||
point.lifetime = 0;
|
||||
point.maxLifetime = params.lifespan * 100 + Math.random() * 50;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function calculateVoronoi() {
|
||||
const cells = points.map(point => ({
|
||||
x: point.x,
|
||||
y: point.y,
|
||||
size: point.size
|
||||
}));
|
||||
|
||||
cellColors.length = 0;
|
||||
for (let i = 0; i < cells.length; i++) {
|
||||
cellColors.push({
|
||||
r: 50 + Math.sin(Date.now() * 0.001 + i) * 20,
|
||||
g: 50 + Math.cos(Date.now() * 0.001 + i * 0.7) * 20,
|
||||
b: 50 + Math.sin(Date.now() * 0.001 + i * 1.3) * 20
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function drawVoronoi() {
|
||||
const imageData = ctx.createImageData(canvas.width, canvas.height);
|
||||
const data = imageData.data;
|
||||
|
||||
for (let y = 0; y < canvas.height; y++) {
|
||||
for (let x = 0; x < canvas.width; x++) {
|
||||
let minDist = Infinity;
|
||||
let cellIndex = 0;
|
||||
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const dx = points[i].x - x;
|
||||
const dy = points[i].y - y;
|
||||
const dist = Math.sqrt(dx * dx + dy * dy) / points[i].size;
|
||||
|
||||
if (dist < minDist) {
|
||||
minDist = dist;
|
||||
cellIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
const color = cellColors[cellIndex];
|
||||
const idx = (y * canvas.width + x) * 4;
|
||||
data[idx] = color.r;
|
||||
data[idx + 1] = color.g;
|
||||
data[idx + 2] = color.b;
|
||||
data[idx + 3] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
}
|
||||
|
||||
function drawPoints() {
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
points.forEach(point => {
|
||||
ctx.beginPath();
|
||||
ctx.arc(point.x, point.y, point.size * 0.5, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
});
|
||||
}
|
||||
|
||||
function animate() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
updatePoints();
|
||||
calculateVoronoi();
|
||||
drawVoronoi();
|
||||
drawPoints();
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
init();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue