birth: Voronoi Currents Wavering

This commit is contained in:
motd_admin 2026-09-13 06:21:23 +00:00
parent cbc2156c69
commit 54e818f4bb

229
index.html Normal file
View file

@ -0,0 +1,229 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voronoi Dreamscape</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
}
canvas {
display: block;
width: 100vw;
height: 100vh;
}
#attribution {
position: fixed;
bottom: 10px;
right: 10px;
color: rgba(255, 255, 255, 0.3);
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');
// Set canvas to full window size
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Voronoi parameters
const params = {
points: Math.floor(150 + 200 * 0.5), // density 0.5
motion: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: 1.08,
tone: {
anger: 0.00,
sadness: 0.00,
curiosity: 0.80,
dryness: 0.90,
playfulness: 0.20,
tension: 0.00
}
};
// Generate voronoi cells
function generateCells() {
const cells = [];
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
// Generate points with motion-affected positions
for (let i = 0; i < params.points; i++) {
const angle = Math.random() * Math.PI * 2;
const distance = Math.random() * Math.min(canvas.width, canvas.height) * 0.4;
const baseX = centerX + Math.cos(angle) * distance;
const baseY = centerY + Math.sin(angle) * distance;
// Add some motion
const stepX = (Math.random() - 0.5) * 2 * params.motion;
const stepY = (Math.random() - 0.5) * 2 * params.motion;
cells.push({
x: baseX,
y: baseY,
vx: stepX,
vy: stepY,
lifespan: params.lifespan * 1000 + Math.random() * 500,
createdAt: Date.now(),
color: getCellColor()
});
}
return cells;
}
// Get cell color based on tone parameters
function getCellColor() {
const hue = 180 + Math.random() * 30; // Teals (curiosity)
const saturation = 30 + params.tone.dryness * 70; // Lower for dryness
const lightness = 70 - params.tone.sadness * 40; // Brighter for dryness
const alpha = 0.7 + Math.random() * 0.3;
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
}
// Calculate voronoi diagram
function calculateVoronoi(cells) {
const diagram = [];
const cellsCopy = [...cells];
for (let i = 0; i < cellsCopy.length; i++) {
const cell = cellsCopy[i];
const neighbors = [];
for (let j = 0; j < cellsCopy.length; j++) {
if (i !== j) {
const dx = cell.x - cellsCopy[j].x;
const dy = cell.y - cellsCopy[j].y;
const distance = Math.sqrt(dx * dx + dy * dy);
neighbors.push({
index: j,
distance: distance
});
}
}
// Sort neighbors by distance to find closest ones
neighbors.sort((a, b) => a.distance - b.distance);
// Limit number of connections based on connectedness
const connectionCount = Math.max(1, Math.floor(params.connectedness * 3));
diagram.push({
point: cell,
neighbors: neighbors.slice(0, connectionCount).map(n => cellsCopy[n.index])
});
}
return diagram;
}
// Draw voronoi diagram
function drawVoronoi(diagram) {
// Clear with semi-transparent background for trails
ctx.fillStyle = `rgba(0, 0, 0, ${0.05 + params.tone.dryness * 0.1})`;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw edges between connected cells
ctx.strokeStyle = 'rgba(180, 220, 220, 0.3)';
ctx.lineWidth = 1 + params.tone.dryness * 0.5;
for (const cell of diagram) {
for (const neighbor of cell.neighbors) {
ctx.beginPath();
ctx.moveTo(cell.point.x, cell.point.y);
ctx.lineTo(neighbor.x, neighbor.y);
ctx.stroke();
}
}
// Draw cell points
for (const cell of diagram) {
ctx.beginPath();
ctx.arc(cell.point.x, cell.point.y, 2 + params.complexity * 2, 0, Math.PI * 2);
ctx.fillStyle = cell.point.color;
ctx.fill();
}
}
// Update cell positions
function updateCells(cells) {
const now = Date.now();
for (const cell of cells) {
// Add some noise to movement
cell.vx += (Math.random() - 0.5) * 0.05 * params.motion;
cell.vy += (Math.random() - 0.5) * 0.05 * params.motion;
// Apply damping
cell.vx *= 0.95;
cell.vy *= 0.95;
cell.x += cell.vx;
cell.y += cell.vy;
// Wrap around edges
if (cell.x < 0) cell.x = canvas.width;
if (cell.x > canvas.width) cell.x = 0;
if (cell.y < 0) cell.y = canvas.height;
if (cell.y > canvas.height) cell.y = 0;
// Fade color as lifespan decreases
const age = now - cell.createdAt;
if (age > cell.lifespan) {
cell.color = cell.color.replace(/[\d.]+\)$/, `${parseFloat(cell.color.match(/[\d.]+\)/)[0]) - 0.01})`);
if (parseFloat(cell.color.match(/[\d.]+\)/)[0]) <= 0.3) {
// Respawn cell occasionally
if (Math.random() < 0.01) {
cell.x = Math.random() * canvas.width;
cell.y = Math.random() * canvas.height;
cell.vx = (Math.random() - 0.5) * 0.5 * params.motion;
cell.vy = (Math.random() - 0.5) * 0.5 * params.motion;
cell.createdAt = now;
cell.color = getCellColor();
}
}
}
}
return cells;
}
// Main animation loop
function animate() {
// Generate initial cells on first frame
if (!window.cells) {
window.cells = generateCells();
}
window.cells = updateCells(window.cells);
const diagram = calculateVoronoi(window.cells);
drawVoronoi(diagram);
requestAnimationFrame(animate);
}
// Start animation
animate();
</script>
</body>
</html>