birth: Voronoi Pulse Fields
This commit is contained in:
parent
544be49ca4
commit
582e8c8f35
1 changed files with 193 additions and 0 deletions
193
index.html
Normal file
193
index.html
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Voronoi Dreams</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a1a;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
left: 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');
|
||||
|
||||
// Set canvas to full window size
|
||||
function resizeCanvas() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
window.addEventListener('resize', resizeCanvas);
|
||||
resizeCanvas();
|
||||
|
||||
// Parameters
|
||||
const params = {
|
||||
motion: 0.463,
|
||||
density: 0.549,
|
||||
complexity: 0.417,
|
||||
connectedness: 0.617,
|
||||
lifespan: 0.548,
|
||||
survivingNodes: 30,
|
||||
branchCount: 28,
|
||||
loops: 339,
|
||||
maxDepth: 21,
|
||||
thicknessRatio: 1.25,
|
||||
fractalDim: 0.883,
|
||||
finalEnergy: 172.4,
|
||||
pulse: { avg: 0.38, min: 0.30, max: 1.60 },
|
||||
tone: { anger: 0.00, sadness: 0.00, curiosity: 0.70, dryness: 0.90, playfulness: 0.10, tension: 0.00 }
|
||||
};
|
||||
|
||||
// Voronoi system
|
||||
class VoronoiCell {
|
||||
constructor(x, y, index) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.index = index;
|
||||
this.energy = Math.random() * params.finalEnergy / params.survivingNodes;
|
||||
this.lifespan = params.lifespan;
|
||||
this.velocity = {
|
||||
x: (Math.random() - 0.5) * params.motion * 2,
|
||||
y: (Math.random() - 0.5) * params.motion * 2
|
||||
};
|
||||
this.connections = [];
|
||||
this.color = `hsl(${Math.random() * 120 + 180}, ${70 + Math.random() * 30}%, ${20 + Math.random() * 10}%)`;
|
||||
}
|
||||
|
||||
update(neighbors) {
|
||||
// Movement influenced by neighbors
|
||||
if (neighbors.length > 0) {
|
||||
const avgX = neighbors.reduce((sum, n) => sum + n.x, 0) / neighbors.length;
|
||||
const avgY = neighbors.reduce((sum, n) => sum + n.y, 0) / neighbors.length;
|
||||
this.velocity.x += (avgX - this.x) * 0.01 * params.connectedness;
|
||||
this.velocity.y += (avgY - this.y) * 0.01 * params.connectedness;
|
||||
}
|
||||
|
||||
// Limit velocity
|
||||
this.velocity.x = Math.min(Math.max(this.velocity.x, -0.5), 0.5);
|
||||
this.velocity.y = Math.min(Math.max(this.velocity.y, -0.5), 0.5);
|
||||
|
||||
// Update position
|
||||
this.x += this.velocity.x;
|
||||
this.y += this.velocity.y;
|
||||
|
||||
// Boundary check
|
||||
if (this.x < 0 || this.x > canvas.width) this.velocity.x *= -1;
|
||||
if (this.y < 0 || this.y > canvas.height) this.velocity.y *= -1;
|
||||
|
||||
// Energy decay
|
||||
this.energy *= 0.995;
|
||||
|
||||
// Color based on energy and tone
|
||||
const energyFactor = this.energy / params.finalEnergy;
|
||||
const hue = 180 + energyFactor * 60;
|
||||
const saturation = 50 + energyFactor * 50;
|
||||
const lightness = 20 + energyFactor * 30;
|
||||
this.color = `hsl(${hue}, ${saturation}%, ${lightness}%)`;
|
||||
}
|
||||
|
||||
connect(other) {
|
||||
if (!this.connections.includes(other.index) && Math.random() < params.connectedness) {
|
||||
this.connections.push(other.index);
|
||||
other.connections.push(this.index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create Voronoi system
|
||||
const cells = [];
|
||||
const connections = [];
|
||||
const maxCells = Math.max(20, Math.floor(params.density * 100));
|
||||
|
||||
for (let i = 0; i < maxCells; i++) {
|
||||
cells.push(new VoronoiCell(
|
||||
Math.random() * canvas.width,
|
||||
Math.random() * canvas.height,
|
||||
i
|
||||
));
|
||||
}
|
||||
|
||||
// Connect cells based on distance
|
||||
for (let i = 0; i < cells.length; i++) {
|
||||
for (let j = i + 1; j < cells.length; j++) {
|
||||
const dx = cells[i].x - cells[j].x;
|
||||
const dy = cells[i].y - cells[j].y;
|
||||
const distance = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (distance < 150 * (1 - params.complexity)) {
|
||||
cells[i].connect(cells[j]);
|
||||
connections.push({ from: i, to: j });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Animation
|
||||
let frameCount = 0;
|
||||
|
||||
function animate() {
|
||||
// Clear with semi-transparent background for trail effect
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Update and draw cells
|
||||
cells.forEach(cell => cell.update(cells.filter(c => cell.connections.includes(c.index))));
|
||||
|
||||
// Draw connections
|
||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
|
||||
ctx.lineWidth = params.thicknessRatio;
|
||||
connections.forEach(conn => {
|
||||
const from = cells[conn.from];
|
||||
const to = cells[conn.to];
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(from.x, from.y);
|
||||
ctx.lineTo(to.x, to.y);
|
||||
ctx.stroke();
|
||||
});
|
||||
|
||||
// Draw cells
|
||||
cells.forEach(cell => {
|
||||
if (cell.energy > 0) {
|
||||
ctx.fillStyle = cell.color;
|
||||
ctx.beginPath();
|
||||
ctx.arc(cell.x, cell.y, 2 + cell.energy / params.finalEnergy * 5, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
|
||||
// Draw connection dots
|
||||
cell.connections.forEach(connIdx => {
|
||||
const connCell = cells[connIdx];
|
||||
ctx.beginPath();
|
||||
ctx.arc(connCell.x, connCell.y, 1, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
frameCount++;
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
Loading…
Add table
Reference in a new issue