185 lines
No EOL
6 KiB
HTML
185 lines
No EOL
6 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 Fracture</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: #333;
|
|
font-size: 10px;
|
|
opacity: 0.3;
|
|
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 from prompt
|
|
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, sadness: 0, curiosity: 0.1, dryness: 0.9, playfulness: 0, tension: 0 }
|
|
};
|
|
|
|
// Color palette based on dryness
|
|
const bgColor = '#0a0a0a';
|
|
const edgeColor = `rgba(200, 200, 200, ${0.7 + params.tone.dryness * 0.3})`;
|
|
const fillColor = `rgba(150, 150, 150, ${0.2 + params.tone.dryness * 0.2})`;
|
|
|
|
// Voronoi cells
|
|
let points = [];
|
|
const numPoints = Math.max(50, Math.floor(params.density * 200 + 100));
|
|
|
|
// Initialize points
|
|
function initPoints() {
|
|
points = [];
|
|
for (let i = 0; i < numPoints; 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,
|
|
size: 1 + Math.random() * 5 * params.complexity,
|
|
originalSize: 1 + Math.random() * 5 * params.complexity,
|
|
lifespan: params.lifespan,
|
|
maxLifespan: 0.5 + Math.random() * 0.5 * params.lifespan
|
|
});
|
|
}
|
|
}
|
|
|
|
initPoints();
|
|
|
|
// Pulse animation
|
|
let pulse = params.pulse.avg;
|
|
let pulseDir = 1;
|
|
|
|
function updatePulse() {
|
|
pulse += (pulseDir * 0.005 * (params.pulse.max - params.pulse.min)) * params.motion;
|
|
if (pulse > params.pulse.max || pulse < params.pulse.min) {
|
|
pulseDir *= -1;
|
|
}
|
|
}
|
|
|
|
// Voronoi diagram calculation
|
|
function calculateVoronoi() {
|
|
// Reset cells
|
|
const cells = points.map(p => ({ points: [], edges: [] }));
|
|
|
|
// Find cell neighbors (Delaunay triangulation approximation)
|
|
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);
|
|
const avgSize = (points[i].size + points[j].size) / 2;
|
|
|
|
if (dist < avgSize * 2) {
|
|
cells[i].edges.push(j);
|
|
cells[j].edges.push(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
return cells;
|
|
}
|
|
|
|
// Draw everything
|
|
function draw() {
|
|
// Clear with fade effect
|
|
ctx.fillStyle = `rgba(0, 0, 0, 0.05)`;
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
// Update points
|
|
updatePulse();
|
|
points.forEach(p => {
|
|
// Movement
|
|
p.x += p.vx * pulse;
|
|
p.y += p.vy * pulse;
|
|
|
|
// Boundary check
|
|
if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
|
|
if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
|
|
|
|
// Lifespan effect
|
|
p.lifespan -= 0.001 * (1 - params.lifespan);
|
|
if (p.lifespan <= 0) {
|
|
points.splice(points.indexOf(p), 1);
|
|
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,
|
|
size: p.originalSize,
|
|
originalSize: p.originalSize,
|
|
lifespan: 1,
|
|
maxLifespan: p.maxLifespan
|
|
});
|
|
}
|
|
});
|
|
|
|
// Calculate Voronoi
|
|
const cells = calculateVoronoi();
|
|
|
|
// Draw Voronoi edges
|
|
ctx.strokeStyle = edgeColor;
|
|
ctx.lineWidth = 1;
|
|
|
|
cells.forEach((cell, i) => {
|
|
cell.edges.forEach(neighbor => {
|
|
const p1 = points[i];
|
|
const p2 = points[neighbor];
|
|
|
|
// Only draw if we haven't drawn this edge before
|
|
if (i < neighbor) {
|
|
ctx.beginPath();
|
|
ctx.moveTo(p1.x, p1.y);
|
|
ctx.lineTo(p2.x, p2.y);
|
|
ctx.stroke();
|
|
}
|
|
});
|
|
});
|
|
|
|
// Draw points with size based on complexity
|
|
ctx.fillStyle = fillColor;
|
|
points.forEach(p => {
|
|
ctx.beginPath();
|
|
ctx.arc(p.x, p.y, p.size * (0.5 + params.complexity), 0, Math.PI * 2);
|
|
ctx.fill();
|
|
});
|
|
|
|
requestAnimationFrame(draw);
|
|
}
|
|
|
|
draw();
|
|
</script>
|
|
</body>
|
|
</html> |