birth: Flowing Particles in Silence

This commit is contained in:
motd_admin 2026-11-13 18:21:27 +00:00
parent 118691b405
commit 847c319b3c

228
index.html Normal file
View file

@ -0,0 +1,228 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flow Field Drift</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
}
#attribution {
position: absolute;
bottom: 20px;
left: 20px;
color: #555;
font-size: 10px;
z-index: 100;
}
canvas {
display: block;
}
</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();
// Flow field parameters
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.0, sadness: 0.0, curiosity: 0.1, dryness: 0.9, playfulness: 0.0, tension: 0.0 }
};
// Particle system
const particles = [];
const gridSize = 20;
const field = [];
const cols = Math.ceil(canvas.width / gridSize) + 1;
const rows = Math.ceil(canvas.height / gridSize) + 1;
// Initialize field
for (let i = 0; i < cols * rows; i++) {
field[i] = {
vx: 0,
vy: 0,
tx: 0,
ty: 0
};
}
// Create particles
const particleCount = Math.max(50, Math.floor(params.density * 200));
for (let i = 0; i < particleCount; i++) {
particles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
size: Math.random() * 2 + 1,
speed: (Math.random() * 0.5 + 0.5) * params.motion,
angle: Math.random() * Math.PI * 2,
life: params.lifespan * 100 + Math.random() * 50,
maxLife: params.lifespan * 100 + Math.random() * 50,
pulse: params.pulse.avg + (Math.random() * 2 - 1) * (params.pulse.max - params.pulse.min) * 0.5,
trail: []
});
}
function updateField() {
const time = Date.now() * 0.001;
const scale = 0.002 + params.complexity * 0.01;
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
const index = y * cols + x;
const nx = x / cols * scale;
const ny = y / rows * scale;
field[index].tx = nx;
field[index].ty = ny;
// Perlin-like noise for field
const angle = (
Math.sin(nx * 10 + time * params.motion) * 2 +
Math.cos(ny * 10 + time * params.motion) * 2 +
Math.sin(time * 0.1) * 5
) * (0.5 + params.connectedness * 0.5);
field[index].vx = Math.cos(angle);
field[index].vy = Math.sin(angle);
}
}
}
function updateParticles() {
particles.forEach(particle => {
const gridX = Math.floor(particle.x / gridSize);
const gridY = Math.floor(particle.y / gridSize);
const index = gridY * cols + gridX;
if (index >= 0 && index < field.length) {
const flow = field[index];
particle.angle = Math.atan2(flow.vy, flow.vx);
}
const moveX = Math.cos(particle.angle) * particle.speed * particle.pulse;
const moveY = Math.sin(particle.angle) * particle.speed * particle.pulse;
particle.x += moveX;
particle.y += moveY;
if (particle.x < 0) particle.x = canvas.width;
if (particle.x > canvas.width) particle.x = 0;
if (particle.y < 0) particle.y = canvas.height;
if (particle.y > canvas.height) particle.y = 0;
particle.life--;
// Add to trail
particle.trail.push({
x: particle.x,
y: particle.y,
life: particle.life
});
// Keep trail length proportional to complexity
const trailLength = 5 + Math.floor(params.complexity * 20);
if (particle.trail.length > trailLength) {
particle.trail.shift();
}
});
}
function draw() {
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw field (subtle)
if (params.dryness < 0.7) {
ctx.strokeStyle = `rgba(255, 255, 255, ${0.1 * (1 - params.dryness)})`;
ctx.lineWidth = 1;
for (let y = 0; y < rows; y += 2) {
for (let x = 0; x < cols; x += 2) {
const index = y * cols + x;
const flow = field[index];
const startX = x * gridSize;
const startY = y * gridSize;
const endX = startX + flow.vx * gridSize * 2;
const endY = startY + flow.vy * gridSize * 2;
ctx.beginPath();
ctx.moveTo(startX, startY);
ctx.lineTo(endX, endY);
ctx.stroke();
}
}
}
// Draw particles and trails
particles.forEach(particle => {
// Draw trail
particle.trail.forEach((point, i) => {
const alpha = (point.life / particle.maxLife) * 0.8;
const size = particle.size * (i / particle.trail.length) * 0.8;
ctx.beginPath();
ctx.arc(point.x, point.y, size, 0, Math.PI * 2);
ctx.fillStyle = `rgba(255, 255, 255, ${alpha * (1 - params.dryness)})`;
ctx.fill();
});
// Draw particle
ctx.beginPath();
ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
ctx.fillStyle = `rgba(255, 255, 255, ${(particle.life / particle.maxLife) * (1 - params.dryness)})`;
ctx.fill();
});
// Remove dead particles
for (let i = particles.length - 1; i >= 0; i--) {
if (particles[i].life <= 0 && Math.random() < 0.1) {
particles.splice(i, 1);
// Replace with new particle at edges
particles.push({
x: Math.random() < 0.5 ? 0 : canvas.width,
y: Math.random() * canvas.height,
size: Math.random() * 2 + 1,
speed: (Math.random() * 0.5 + 0.5) * params.motion,
angle: Math.random() * Math.PI * 2,
life: params.lifespan * 100 + Math.random() * 50,
maxLife: params.lifespan * 100 + Math.random() * 50,
pulse: params.pulse.avg + (Math.random() * 2 - 1) * (params.pulse.max - params.pulse.min) * 0.5,
trail: []
});
}
}
}
function animate() {
updateField();
updateParticles();
draw();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>