birth: Pulsing Voronoi Membrane
This commit is contained in:
parent
4de17d064f
commit
bcc672a9bc
1 changed files with 225 additions and 0 deletions
225
index.html
Normal file
225
index.html
Normal file
|
|
@ -0,0 +1,225 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Voronoi Organism</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
font-family: 'Courier New', monospace;
|
||||
color: #ccc;
|
||||
}
|
||||
#canvas {
|
||||
display: block;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
font-size: 10px;
|
||||
opacity: 0.5;
|
||||
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');
|
||||
|
||||
// Resize canvas
|
||||
function resizeCanvas() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
window.addEventListener('resize', resizeCanvas);
|
||||
resizeCanvas();
|
||||
|
||||
// Parameters
|
||||
const params = {
|
||||
motion: 0.436,
|
||||
density: 0.513,
|
||||
complexity: 0.599,
|
||||
connectedness: 0.602,
|
||||
lifespan: 0.474,
|
||||
pulse: {
|
||||
avg: 0.62,
|
||||
min: 0.30,
|
||||
max: 2.00
|
||||
},
|
||||
tone: {
|
||||
anger: 0.00,
|
||||
sadness: 0.00,
|
||||
curiosity: 0.70,
|
||||
dryness: 0.90,
|
||||
playfulness: 0.10,
|
||||
tension: 0.00
|
||||
}
|
||||
};
|
||||
|
||||
// Voronoi generator
|
||||
class VoronoiOrganism {
|
||||
constructor() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
this.points = [];
|
||||
this.cells = [];
|
||||
this.age = 0;
|
||||
this.pulseTimer = 0;
|
||||
this.pulseState = params.pulse.avg;
|
||||
|
||||
// Calculate point count based on density
|
||||
const baseCount = 200;
|
||||
const pointCount = Math.floor(baseCount * params.density);
|
||||
|
||||
// Create points
|
||||
for (let i = 0; i < pointCount; i++) {
|
||||
this.points.push({
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: 0,
|
||||
vy: 0,
|
||||
radius: 2 + Math.random() * 8 * params.pulseState,
|
||||
life: 0,
|
||||
maxLife: 100 + Math.random() * 50 * params.lifespan
|
||||
});
|
||||
}
|
||||
|
||||
// Precompute distance matrix for connectedness
|
||||
this.distanceMatrix = [];
|
||||
for (let i = 0; i < this.points.length; i++) {
|
||||
this.distanceMatrix[i] = [];
|
||||
for (let j = 0; j < this.points.length; j++) {
|
||||
const dx = this.points[i].x - this.points[j].x;
|
||||
const dy = this.points[i].y - this.points[j].y;
|
||||
this.distanceMatrix[i][j] = Math.sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
this.age++;
|
||||
this.pulseTimer += 0.01;
|
||||
|
||||
// Update pulse state
|
||||
const pulseVariation = params.pulse.max - params.pulse.min;
|
||||
this.pulseState = params.pulse.avg + Math.sin(this.pulseTimer) * pulseVariation * 0.5;
|
||||
|
||||
// Update points
|
||||
for (let i = 0; i < this.points.length; i++) {
|
||||
const p = this.points[i];
|
||||
|
||||
// Add movement based on motion parameter
|
||||
const baseSpeed = 0.2 * params.motion * this.pulseState;
|
||||
p.vx += (Math.random() - 0.5) * baseSpeed;
|
||||
p.vy += (Math.random() - 0.5) * baseSpeed;
|
||||
|
||||
// Dampen velocity
|
||||
p.vx *= 0.9;
|
||||
p.vy *= 0.9;
|
||||
|
||||
// Update position
|
||||
p.x += p.vx;
|
||||
p.y += p.vy;
|
||||
|
||||
// Boundary check
|
||||
if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
|
||||
if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
|
||||
|
||||
// Update life
|
||||
p.life++;
|
||||
if (p.life > p.maxLife) {
|
||||
// Respawn point
|
||||
p.x = Math.random() * canvas.width;
|
||||
p.y = Math.random() * canvas.height;
|
||||
p.life = 0;
|
||||
p.maxLife = 100 + Math.random() * 50 * params.lifespan;
|
||||
p.radius = 2 + Math.random() * 8 * this.pulseState;
|
||||
}
|
||||
|
||||
// Calculate cell boundaries
|
||||
const edges = [];
|
||||
for (let j = 0; j < this.points.length; j++) {
|
||||
if (i !== j) {
|
||||
const dx = this.points[j].x - p.x;
|
||||
const dy = this.points[j].y - p.y;
|
||||
const distance = this.distanceMatrix[i][j];
|
||||
if (distance > 0) {
|
||||
const edgeX = p.x + (dx / distance) * p.radius;
|
||||
const edgeY = p.y + (dy / distance) * p.radius;
|
||||
edges.push({x: edgeX, y: edgeY});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store cell for drawing
|
||||
this.cells[i] = edges;
|
||||
}
|
||||
}
|
||||
|
||||
draw() {
|
||||
// Clear with slight fade
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Calculate color based on tone
|
||||
const teal = 50 + Math.floor(params.tone.curiosity * 50);
|
||||
const gray = 30 + Math.floor(params.tone.dryness * 25);
|
||||
const color = `hsl(${teal}, 80%, ${gray}%)`;
|
||||
|
||||
// Draw cells with varying opacity based on lifespan
|
||||
for (let i = 0; i < this.cells.length; i++) {
|
||||
const cell = this.cells[i];
|
||||
if (cell.length > 2) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cell[0].x, cell[0].y);
|
||||
|
||||
for (let j = 1; j < cell.length; j++) {
|
||||
ctx.lineTo(cell[j].x, cell[j].y);
|
||||
}
|
||||
|
||||
const lifeRatio = this.points[i].life / this.points[i].maxLife;
|
||||
const alpha = 0.3 + 0.7 * (1 - lifeRatio * lifeRatio);
|
||||
ctx.fillStyle = color.replace('hsl(', 'hsla(').replace(')', `, ${alpha})`);
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = color;
|
||||
ctx.lineWidth = 0.5;
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
// Draw points (smaller circles)
|
||||
for (let i = 0; i < this.points.length; i++) {
|
||||
const p = this.points[i];
|
||||
const lifeRatio = p.life / p.maxLife;
|
||||
const pointAlpha = 0.5 * (1 - lifeRatio);
|
||||
ctx.beginPath();
|
||||
ctx.arc(p.x, p.y, p.radius * 0.3, 0, Math.PI * 2);
|
||||
ctx.fillStyle = `hsla(${teal}, 80%, ${gray}%, ${pointAlpha})`;
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Main animation
|
||||
const organism = new VoronoiOrganism();
|
||||
|
||||
function animate() {
|
||||
organism.update();
|
||||
organism.draw();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue