birth: Voronoi Quiver

This commit is contained in:
motd_admin 2026-09-30 06:21:22 +00:00
parent d7021ba2bb
commit 5c9880736c

158
index.html Normal file
View file

@ -0,0 +1,158 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Voronoi Quiver</title>
<style>
body { margin: 0; overflow: hidden; background: #0a0a0a; }
canvas { display: block; }
#attribution { position: fixed; bottom: 10px; right: 10px; color: #444; font-family: monospace; font-size: 10px; }
</style>
</head>
<body>
<canvas id="c"></canvas>
<div id="attribution">neurameba · motd.social</div>
<script>
const canvas = document.getElementById('c');
const c = canvas.getContext('2d');
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resize);
resize();
// Voronoi parameters
const points = [];
const weights = [];
const thresholds = [];
let pulse = 1;
// Initialize
function init() {
points.length = 0;
weights.length = 0;
thresholds.length = 0;
const count = Math.floor(200 + 300 * 0.5);
for (let i = 0; i < count; i++) {
points.push([Math.random() * canvas.width, Math.random() * canvas.height]);
weights.push(Math.random() * 0.8 + 0.2);
thresholds.push(Math.random() * 0.5 + 0.5);
}
}
init();
// Voronoi cell calculation
function getVoronoi(x, y) {
let minDist = Infinity;
let minIndex = 0;
for (let i = 0; i < points.length; i++) {
const px = points[i][0];
const py = points[i][1];
const dx = px - x;
const dy = py - y;
const dist = Math.sqrt(dx*dx + dy*dy) * weights[i];
if (dist < minDist) {
minDist = dist;
minIndex = i;
}
}
return points[minIndex];
}
// Animation
let time = 0;
function animate() {
c.fillStyle = 'rgba(0, 0, 0, 0.1)';
c.fillRect(0, 0, canvas.width, canvas.height);
time += 0.01;
// Update points
const speed = 0.5 + 0.5 * 0.5; // motion affects speed
for (let i = 0; i < points.length; i++) {
const angle = time * (0.5 + Math.random() * 0.5) * speed;
const radius = 20 + Math.sin(time * 0.3 + i) * 5;
points[i][0] += Math.cos(angle) * radius * 0.01;
points[i][1] += Math.sin(angle) * radius * 0.01;
// Boundary bounce
if (points[i][0] < 0) points[i][0] = canvas.width;
if (points[i][0] > canvas.width) points[i][0] = 0;
if (points[i][1] < 0) points[i][1] = canvas.height;
if (points[i][1] > canvas.height) points[i][1] = 0;
}
// Pulse effect
pulse = 1.0 + 0.05 * Math.sin(time * 2);
c.lineWidth = 1.5 * pulse;
// Draw connections
const connectedness = 0.5;
const maxConnections = Math.floor(5 + 5 * connectedness);
const maxDist = 100 + 50 * (1 - density);
for (let i = 0; i < points.length; i++) {
const p1 = points[i];
// Draw cell outline
c.strokeStyle = `hsl(0, 0%, ${70 + Math.sin(time + i * 0.1) * 10}%)`;
c.beginPath();
const cells = [];
const cellSize = 3;
for (let x = 0; x < canvas.width; x += cellSize) {
for (let y = 0; y < canvas.height; y += cellSize) {
const nearest = getVoronoi(x, y);
const dist = Math.sqrt((nearest[0] - x)**2 + (nearest[1] - y)**2);
if (dist < maxDist * 0.5) {
cells.push([x, y]);
}
}
}
// Simplified cell drawing
c.beginPath();
for (let j = 0; j < cells.length; j++) {
if (j === 0) c.moveTo(cells[j][0], cells[j][1]);
else c.lineTo(cells[j][0], cells[j][1]);
}
c.stroke();
// Draw connections
const connections = [];
for (let j = 0; j < points.length; j++) {
if (i !== j) {
const p2 = points[j];
const dx = p2[0] - p1[0];
const dy = p2[1] - p1[1];
const dist = Math.sqrt(dx*dx + dy*dy);
if (dist < maxDist && Math.random() < connectedness * 0.1) {
connections.push([p1[0], p1[1], p2[0], p2[1]]);
}
}
}
// Draw connections
c.strokeStyle = `rgba(255, 255, 255, ${0.1 + connectedness * 0.2})`;
c.lineWidth = 0.5 * pulse;
c.beginPath();
for (const conn of connections) {
c.moveTo(conn[0], conn[1]);
c.lineTo(conn[2], conn[3]);
}
c.stroke();
}
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>