216 lines
No EOL
7.1 KiB
HTML
216 lines
No EOL
7.1 KiB
HTML
```html
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>voronoi flux</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
color: #ccc;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: fixed;
|
|
bottom: 10px;
|
|
left: 10px;
|
|
font-size: 10px;
|
|
opacity: 0.5;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="c"></canvas>
|
|
<div id="attribution">neurameba · motd.social</div>
|
|
<script>
|
|
const canvas = document.getElementById('c');
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
function resize() {
|
|
canvas.width = innerWidth;
|
|
canvas.height = innerHeight;
|
|
}
|
|
addEventListener('resize', resize);
|
|
resize();
|
|
|
|
// Parameters derived from the abstract specs
|
|
const params = {
|
|
motion: 0.493,
|
|
density: 0.545,
|
|
complexity: 0.512,
|
|
connectedness: 0.516,
|
|
lifespan: 0.408,
|
|
pulse: { avg: 0.49, min: 0.30, max: 1.95 },
|
|
tone: { anger: 0.00, sadness: 0.00, curiosity: 0.70, dryness: 0.90, playfulness: 0.10, tension: 0.00 }
|
|
};
|
|
|
|
// Voronoi setup
|
|
const points = [];
|
|
const cells = [];
|
|
const edges = [];
|
|
const edgesToProcess = [];
|
|
const activePoints = [];
|
|
const deadPoints = [];
|
|
|
|
// Palette based on dryness + curiosity
|
|
const palette = [
|
|
'#e0e0e0', '#d0d0d0', '#c0c0c0', '#b0b0b0', '#a0a0a0',
|
|
'#90e0e0', '#80d0d0', '#70c0c0', '#60b0b0', '#50a0a0'
|
|
];
|
|
|
|
function init() {
|
|
// Generate seed points
|
|
for (let i = 0; i < 94; i++) {
|
|
points.push({
|
|
x: Math.random() * canvas.width,
|
|
y: Math.random() * canvas.height,
|
|
vx: (Math.random() - 0.5) * 0.5 * params.motion,
|
|
vy: (Math.random() - 0.5) * 0.5 * params.motion,
|
|
alive: true,
|
|
energy: 503.1 * (0.3 + Math.random() * 0.7) * params.lifespan
|
|
});
|
|
}
|
|
|
|
// Initial Voronoi (simplified)
|
|
computeVoronoi();
|
|
}
|
|
|
|
function computeVoronoi() {
|
|
// Simplified Voronoi by edge expansion from point pairs
|
|
cells.length = 0;
|
|
edges.length = 0;
|
|
edgesToProcess.length = 0;
|
|
|
|
// Find closest pairs
|
|
for (let i = 0; i < points.length; i++) {
|
|
for (let j = i + 1; j < points.length; j++) {
|
|
const dx = points[j].x - points[i].x;
|
|
const dy = points[j].y - points[i].y;
|
|
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
edgesToProcess.push({ i, j, dist });
|
|
}
|
|
}
|
|
|
|
// Sort by distance
|
|
edgesToProcess.sort((a, b) => a.dist - b.dist);
|
|
|
|
// Build Voronoi edges
|
|
const usedEdges = new Set();
|
|
for (const { i, j } of edgesToProcess) {
|
|
if (usedEdges.has(i + ',' + j) || usedEdges.has(j + ',' + i)) continue;
|
|
|
|
const cell1 = cells[i] || (cells[i] = { edges: [], center: { x: points[i].x, y: points[i].y } });
|
|
const cell2 = cells[j] || (cells[j] = { edges: [], center: { x: points[j].x, y: points[j].y } });
|
|
|
|
const edge = {
|
|
p1: i,
|
|
p2: j,
|
|
length: Math.sqrt(
|
|
Math.pow(points[i].x - points[j].x, 2) +
|
|
Math.pow(points[i].y - points[j].y, 2)
|
|
)
|
|
};
|
|
|
|
cell1.edges.push(edge);
|
|
cell2.edges.push(edge);
|
|
edges.push(edge);
|
|
usedEdges.add(i + ',' + j);
|
|
}
|
|
}
|
|
|
|
function updatePoints() {
|
|
points.forEach(p => {
|
|
// Brownian motion scaled by global motion
|
|
p.vx += (Math.random() - 0.5) * 0.01 * params.motion;
|
|
p.vy += (Math.random() - 0.5) * 0.01 * params.motion;
|
|
|
|
// Energy decay based on lifespan and pulse
|
|
const pulseFactor = params.pulse.avg + (Math.random() - 0.05) * (params.pulse.max - params.pulse.min);
|
|
p.energy -= 0.01 * pulseFactor * (1 / (1 + params.lifespan * 2));
|
|
|
|
if (p.energy <= 0) {
|
|
p.alive = false;
|
|
deadPoints.push(p);
|
|
return;
|
|
}
|
|
|
|
// Simple boundary check
|
|
p.x = (p.x + p.vx + canvas.width) % canvas.width;
|
|
p.y = (p.y + p.vy + canvas.height) % canvas.height;
|
|
});
|
|
|
|
// Remove dead points
|
|
points.forEach((p, i) => {
|
|
if (!p.alive) {
|
|
points.splice(i, 1);
|
|
}
|
|
});
|
|
}
|
|
|
|
function draw() {
|
|
ctx.fillStyle = '#0a0a0a';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
// Draw Voronoi cells
|
|
ctx.strokeStyle = palette[Math.floor(Math.random() * palette.length)];
|
|
ctx.lineWidth = 0.8 + Math.random() * 0.4;
|
|
ctx.globalAlpha = 0.6 + Math.random() * 0.3;
|
|
|
|
edges.forEach(edge => {
|
|
if (cells[edge.p1] && cells[edge.p2]) {
|
|
ctx.beginPath();
|
|
ctx.moveTo(cells[edge.p1].center.x, cells[edge.p1].center.y);
|
|
ctx.lineTo(cells[edge.p2].center.x, cells[edge.p2].center.y);
|
|
ctx.stroke();
|
|
}
|
|
});
|
|
|
|
// Draw points
|
|
points.forEach(point => {
|
|
const hue = 160 + (point.energy / 503.1) * 100;
|
|
const sat = 30 + (point.energy / 503.1) * 70;
|
|
const bright = 60 + (point.energy / 503.1) * 40;
|
|
|
|
ctx.fillStyle = `hsl(${hue}, ${sat}%, ${bright}%)`;
|
|
ctx.beginPath();
|
|
ctx.arc(point.x, point.y, 1.5 + (point.energy / 503.1) * 0.5, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
});
|
|
|
|
// Draw connections gently pulsing
|
|
ctx.globalAlpha = 0.3;
|
|
edges.forEach(edge => {
|
|
if (cells[edge.p1] && cells[edge.p2]) {
|
|
const hue = 180 + (edge.length / 100) * 20;
|
|
ctx.strokeStyle = `hsl(${hue}, 60%, 70%)`;
|
|
ctx.lineWidth = 0.5 + Math.sin(Date.now() * 0.001) * 0.3;
|
|
|
|
ctx.beginPath();
|
|
ctx.moveTo(cells[edge.p1].center.x, cells[edge.p1].center.y);
|
|
ctx.lineTo(cells[edge.p2].center.x, cells[edge.p2].center.y);
|
|
ctx.stroke();
|
|
}
|
|
});
|
|
|
|
ctx.globalAlpha = 1;
|
|
}
|
|
|
|
function animate() {
|
|
updatePoints();
|
|
computeVoronoi();
|
|
draw();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
init();
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html>
|
|
``` |