162 lines
No EOL
5.4 KiB
HTML
162 lines
No EOL
5.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Voronoi Drift</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: fixed;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
color: #444;
|
|
font-size: 10px;
|
|
pointer-events: none;
|
|
}
|
|
</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();
|
|
|
|
// Parameters derived from input
|
|
const params = {
|
|
motion: 0.5,
|
|
density: 0.5,
|
|
complexity: 0.5,
|
|
connectedness: 0.5,
|
|
lifespan: 0.5,
|
|
pulse: { avg: 1.1, min: 0.9, max: 1.2 },
|
|
tone: { anger: 0, sadness: 0, curiosity: 0.1, dryness: 0.8, playfulness: 0, tension: 0 }
|
|
};
|
|
|
|
// Voronoi cell structure
|
|
const cells = [];
|
|
const points = [];
|
|
const maxPoints = Math.max(200, 400 * params.density);
|
|
const connections = params.connectedness * 5; // Maximum connections per cell
|
|
|
|
// Initialize points
|
|
for (let i = 0; i < maxPoints; i++) {
|
|
points.push({
|
|
x: Math.random() * canvas.width,
|
|
y: Math.random() * canvas.height,
|
|
vx: (Math.random() - 0.5) * 2 * params.motion,
|
|
vy: (Math.random() - 0.5) * 2 * params.motion,
|
|
energy: Math.random() * params.lifespan,
|
|
color: `hsl(0, 0%, ${params.tone.dryness > 0.7 ? 80 + Math.random() * 10 : 30 + Math.random() * 40}%)`
|
|
});
|
|
}
|
|
|
|
// Create Voronoi diagram
|
|
function createVoronoi() {
|
|
// Simple Voronoi approximation
|
|
cells.length = 0;
|
|
for (let i = 0; i < points.length; i++) {
|
|
const nearest = [];
|
|
for (let j = 0; j < points.length; j++) {
|
|
if (i === j) continue;
|
|
const dx = points[i].x - points[j].x;
|
|
const dy = points[i].y - points[j].y;
|
|
nearest.push({
|
|
index: j,
|
|
distance: dx * dx + dy * dy
|
|
});
|
|
}
|
|
nearest.sort((a, b) => a.distance - b.distance);
|
|
cells.push({
|
|
pointIndex: i,
|
|
neighbors: nearest.slice(0, Math.max(1, Math.floor(connectedness * 5))).map(n => n.index),
|
|
edges: []
|
|
});
|
|
}
|
|
}
|
|
|
|
// Update points
|
|
function updatePoints() {
|
|
for (const point of points) {
|
|
// Apply motion
|
|
point.x += point.vx;
|
|
point.y += point.vy;
|
|
|
|
// Boundary check
|
|
if (point.x < 0) { point.x = canvas.width; point.vx *= -1; }
|
|
if (point.x > canvas.width) { point.x = 0; point.vx *= -1; }
|
|
if (point.y < 0) { point.y = canvas.height; point.vy *= -1; }
|
|
if (point.y > canvas.height) { point.y = 0; point.vy *= -1; }
|
|
|
|
// Energy decay
|
|
point.energy *= 0.99;
|
|
}
|
|
}
|
|
|
|
// Draw Voronoi cells
|
|
function drawVoronoi() {
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
// Draw connections
|
|
ctx.strokeStyle = `rgba(255, 255, 255, ${params.tone.dryness > 0.7 ? 0.3 : 0.6})`;
|
|
ctx.lineWidth = 0.5 + params.complexity * 1.5;
|
|
|
|
for (const cell of cells) {
|
|
const point = points[cell.pointIndex];
|
|
for (const neighborIndex of cell.neighbors) {
|
|
const neighborPoint = points[neighborIndex];
|
|
const dist = Math.sqrt(
|
|
Math.pow(point.x - neighborPoint.x, 2) +
|
|
Math.pow(point.y - neighborPoint.y, 2)
|
|
);
|
|
|
|
if (dist < 200) {
|
|
const alpha = Math.min(1, dist / 300) * params.connectedness;
|
|
ctx.globalAlpha = alpha;
|
|
ctx.beginPath();
|
|
ctx.moveTo(point.x, point.y);
|
|
ctx.lineTo(neighborPoint.x, neighborPoint.y);
|
|
ctx.stroke();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Draw points
|
|
ctx.globalAlpha = 1;
|
|
for (const point of points) {
|
|
ctx.fillStyle = point.color;
|
|
ctx.beginPath();
|
|
ctx.arc(point.x, point.y, 2 + params.complexity * 3, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
}
|
|
}
|
|
|
|
// Animation loop
|
|
function animate() {
|
|
updatePoints();
|
|
createVoronoi();
|
|
drawVoronoi();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |