birth: Fractured Monochrome Voronoi

This commit is contained in:
motd_admin 2026-07-26 01:47:20 +00:00
parent 3174fa7a09
commit 83234a5488

164
index.html Normal file
View file

@ -0,0 +1,164 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voronoi Fracture</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
}
canvas {
display: block;
}
#attribution {
position: absolute;
bottom: 10px;
right: 10px;
color: #444;
font-size: 10px;
z-index: 100;
}
</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 points = [];
const colors = [];
const trails = [];
const maxTrailLength = 30;
// Initialize points based on density
function initPoints() {
const count = Math.floor(100 + 900 * 0.5); // 500 points at density 0.5
for (let i = 0; i < count; i++) {
points.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: (Math.random() - 0.5) * 2 * 0.5, // scaled by motion
vy: (Math.random() - 0.5) * 2 * 0.5,
life: Math.random() * 100 + 50,
maxLife: Math.random() * 100 + 50,
size: Math.random() * 2 + 1
});
// Dryness palette (monochrome with slight variation)
const intensity = 50 + Math.random() * 50;
colors.push(`rgb(${intensity}, ${intensity}, ${intensity})`);
}
}
// Voronoi diagram generation
function generateVoronoi() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.globalAlpha = 1;
// Draw voronoi cells
for (let y = 0; y < canvas.height; y += 2) {
for (let x = 0; x < canvas.width; x += 2) {
let closestDist = Infinity;
let closestIndex = 0;
for (let i = 0; i < points.length; i++) {
const dx = x - points[i].x;
const dy = y - points[i].y;
const dist = dx * dx + dy * dy;
if (dist < closestDist) {
closestDist = dist;
closestIndex = i;
}
}
ctx.fillStyle = colors[closestIndex];
ctx.fillRect(x, y, 2, 2);
}
}
// Draw points with trails
for (let i = 0; i < points.length; i++) {
// Update point position
points[i].x += points[i].vx;
points[i].y += points[i].vy;
// Bounce off edges
if (points[i].x < 0 || points[i].x > canvas.width) points[i].vx *= -1;
if (points[i].y < 0 || points[i].y > canvas.height) points[i].vy *= -1;
// Add to trail
trails[i] = trails[i] || [];
trails[i].push({x: points[i].x, y: points[i].y});
if (trails[i].length > maxTrailLength) trails[i].shift();
// Age points
points[i].life--;
if (points[i].life <= 0) {
points[i] = {
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
vx: (Math.random() - 0.5) * 2 * 0.5,
vy: (Math.random() - 0.5) * 2 * 0.5,
life: Math.random() * 100 + 50,
maxLife: points[i].maxLife,
size: Math.random() * 2 + 1
};
}
// Draw trail
if (trails[i].length > 1) {
ctx.globalAlpha = 0.8;
ctx.strokeStyle = `rgba(120, 120, 120, ${0.3 + 0.7 * (1 - points[i].life / points[i].maxLife)})`;
ctx.lineWidth = points[i].size * 0.5;
ctx.beginPath();
ctx.moveTo(trails[i][0].x, trails[i][0].y);
for (let j = 1; j < trails[i].length; j++) {
ctx.lineTo(trails[i][j].x, trails[i][j].y);
}
ctx.stroke();
}
// Draw point
ctx.globalAlpha = 1;
ctx.fillStyle = colors[i];
ctx.beginPath();
ctx.arc(points[i].x, points[i].y, points[i].size, 0, Math.PI * 2);
ctx.fill();
}
// Occasionally reset colors for dryness effect
if (Math.random() < 0.01) {
for (let i = 0; i < colors.length; i++) {
const intensity = 50 + Math.random() * 50;
colors[i] = `rgb(${intensity}, ${intensity}, ${intensity})`;
}
}
}
function animate() {
generateVoronoi();
requestAnimationFrame(animate);
}
initPoints();
animate();
</script>
</body>
</html>