181 lines
No EOL
5.4 KiB
HTML
181 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 Bloom</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a1a;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: fixed;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
color: rgba(255, 255, 255, 0.3);
|
|
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
|
|
const params = {
|
|
motion: 0.5,
|
|
density: 0.5,
|
|
complexity: 0.5,
|
|
connectedness: 0.5,
|
|
lifespan: 0.5,
|
|
pulse: 1.08,
|
|
tone: {
|
|
anger: 0.00,
|
|
sadness: 0.00,
|
|
curiosity: 0.10,
|
|
dryness: 0.90,
|
|
playfulness: 0.00,
|
|
tension: 0.00
|
|
}
|
|
};
|
|
|
|
// Voronoi setup
|
|
const sites = [];
|
|
const colors = [];
|
|
const points = [];
|
|
const maxPoints = Math.floor(200 + params.density * 800);
|
|
const voronoi = { edges: [] };
|
|
|
|
// Initialize
|
|
function init() {
|
|
sites.length = 0;
|
|
points.length = 0;
|
|
voronoi.edges.length = 0;
|
|
|
|
// Generate sites
|
|
for (let i = 0; i < maxPoints; i++) {
|
|
const x = Math.random() * canvas.width;
|
|
const y = Math.random() * canvas.height;
|
|
sites.push({ x, y });
|
|
points.push({ x, y, vx: 0, vy: 0, lifetime: 0 });
|
|
|
|
// Colors: dryness = monochrome with slight teal
|
|
const base = 50 + Math.random() * 100;
|
|
const tealMix = Math.random() * 20;
|
|
colors.push(`rgb(${base + tealMix}, ${base + tealMix}, ${base + 100 + tealMix})`);
|
|
}
|
|
}
|
|
|
|
init();
|
|
|
|
// Physics
|
|
function updatePoints() {
|
|
const speed = 0.5 + params.motion * 2;
|
|
const connectedFactor = params.connectedness * 0.1;
|
|
|
|
for (let i = 0; i < points.length; i++) {
|
|
const p = points[i];
|
|
const targetX = sites[i].x;
|
|
const targetY = sites[i].y;
|
|
|
|
p.vx += (targetX - p.x) * 0.01 * speed;
|
|
p.vy += (targetY - p.y) * 0.01 * speed;
|
|
|
|
p.vx *= 0.92;
|
|
p.vy *= 0.92;
|
|
|
|
p.x += p.vx;
|
|
p.y += p.vy;
|
|
|
|
// Wrap around edges
|
|
if (p.x < 0) p.x = canvas.width;
|
|
if (p.x > canvas.width) p.x = 0;
|
|
if (p.y < 0) p.y = canvas.height;
|
|
if (p.y > canvas.height) p.y = 0;
|
|
|
|
p.lifetime += 0.001 + params.lifespan * 0.005;
|
|
}
|
|
}
|
|
|
|
// Voronoi calculation (simplified)
|
|
function calculateVoronoi() {
|
|
voronoi.edges.length = 0;
|
|
|
|
for (let i = 0; i < sites.length; i++) {
|
|
for (let j = i + 1; j < sites.length; j++) {
|
|
const a = sites[i];
|
|
const b = sites[j];
|
|
const dist = Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);
|
|
|
|
if (dist < 50 + params.complexity * 100) {
|
|
voronoi.edges.push({
|
|
p1: a,
|
|
p2: b,
|
|
dist: dist
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Drawing
|
|
function draw() {
|
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
const lineWidth = 0.5 + params.complexity * 1.5;
|
|
const opacity = 0.3 + params.connectedness * 0.4;
|
|
|
|
// Draw voronoi edges
|
|
for (const edge of voronoi.edges) {
|
|
ctx.strokeStyle = `rgba(255, 255, 255, ${opacity * 0.7})`;
|
|
ctx.lineWidth = lineWidth * (1 - edge.dist / 100);
|
|
ctx.beginPath();
|
|
ctx.moveTo(edge.p1.x, edge.p1.y);
|
|
ctx.lineTo(edge.p2.x, edge.p2.y);
|
|
ctx.stroke();
|
|
}
|
|
|
|
// Draw points with trails
|
|
for (let i = 0; i < points.length; i++) {
|
|
const p = points[i];
|
|
const size = 1 + Math.sin(p.lifetime * 5) * params.motion * 1.5;
|
|
const alpha = 0.5 + Math.sin(p.lifetime * 3) * 0.3;
|
|
|
|
ctx.fillStyle = `rgba(${colors[i]}, ${alpha})`;
|
|
ctx.beginPath();
|
|
ctx.arc(p.x, p.y, size, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
}
|
|
}
|
|
|
|
// Animation loop
|
|
function animate() {
|
|
updatePoints();
|
|
calculateVoronoi();
|
|
draw();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |