flowing-emulsion-dreams-xvpj/index.html

188 lines
No EOL
6.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flow Field Emulsion</title>
<style>
body { margin: 0; overflow: hidden; background: #0a0a0a; }
canvas { display: block; }
.attribution { position: absolute; bottom: 10px; right: 10px; color: #555; font-family: monospace; font-size: 12px; }
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div class="attribution">neurameba · motd.social</div>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
function resize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resize);
resize();
// Parameters derived from input
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: { avg: 1.05, min: 1.0, max: 1.1 },
tone: { anger: 0, sadness: 0, curiosity: 0.1, dryness: 0.9, playfulness: 0, tension: 0 }
};
// Flow field parameters
const fieldSize = 32;
const fieldWidth = Math.ceil(canvas.width / fieldSize);
const fieldHeight = Math.ceil(canvas.height / fieldSize);
const field = new Array(fieldWidth * fieldHeight);
// Particle system
const particles = [];
const particleCount = Math.floor(params.density * 1500) + 500;
// Initialize field
function initField() {
for (let y = 0; y < fieldHeight; y++) {
for (let x = 0; x < fieldWidth; x++) {
const idx = y * fieldWidth + x;
const angle = Math.random() * Math.PI * 2;
const strength = 0.5 + Math.random() * 0.5;
field[idx] = {
dx: Math.cos(angle) * strength,
dy: Math.sin(angle) * strength
};
}
}
}
// Initialize particles
function initParticles() {
particles.length = 0;
for (let i = 0; i < particleCount; i++) {
particles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
prevX: 0,
prevY: 0,
vx: 0,
vy: 0,
size: 1 + Math.random() * 2,
speed: 0.5 + Math.random() * 0.5,
lifespan: params.lifespan * 100 + 50,
pulse: 1,
hue: params.tone.dryness > 0.5 ? 0 : 180 + Math.random() * 60
});
}
}
// Update field based on motion
function updateField() {
const pulseVariation = params.pulse.avg + (params.pulse.max - params.pulse.min) * (0.5 - Math.random());
for (let y = 0; y < fieldHeight; y++) {
for (let x = 0; x < fieldWidth; x++) {
const idx = y * fieldWidth + x;
const fieldPoint = field[idx];
// Simulate organic flow with slight turbulence
fieldPoint.dx += (Math.random() - 0.5) * 0.1 * params.motion;
fieldPoint.dy += (Math.random() - 0.5) * 0.1 * params.motion;
// Normalize and scale
const length = Math.sqrt(fieldPoint.dx * fieldPoint.dx + fieldPoint.dy * fieldPoint.dy);
if (length > 0) {
fieldPoint.dx = fieldPoint.dx / length * 0.5 * pulseVariation;
fieldPoint.dy = fieldPoint.dy / length * 0.5 * pulseVariation;
}
}
}
}
// Update particles
function updateParticles() {
for (let i = particles.length - 1; i >= 0; i--) {
const p = particles[i];
// Age particle
p.lifespan--;
if (p.lifespan <= 0) {
particles.splice(i, 1);
continue;
}
// Pulse effect
p.pulse = params.pulse.avg + (params.pulse.max - params.pulse.min) * (Math.sin(Date.now() * 0.001) * 0.5 + 0.5);
// Get field influence
const fieldX = Math.floor(p.x / fieldSize);
const fieldY = Math.floor(p.y / fieldSize);
const idx = fieldY * fieldWidth + fieldX;
const fieldPoint = field[idx % field.length];
// Calculate new velocity
p.vx = fieldPoint.dx * p.speed * p.pulse;
p.vy = fieldPoint.dy * p.speed * p.pulse;
// Update position
p.prevX = p.x;
p.prevY = p.y;
p.x += p.vx;
p.y += p.vy;
// Boundary checks
if (p.x < 0 || p.x > canvas.width || p.y < 0 || p.y > canvas.height) {
p.x = Math.random() * canvas.width;
p.y = Math.random() * canvas.height;
}
}
}
// Draw particles with trails
function draw() {
// Fade background slightly
ctx.fillStyle = 'rgba(10, 10, 10, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Use dryness tone (monochrome)
const brightness = 50 + Math.sin(Date.now() * 0.002) * 30;
for (const p of particles) {
// Calculate trail length based on motion
const trailLength = Math.floor(params.motion * 3) + 1;
// Draw trail
ctx.beginPath();
ctx.moveTo(p.x, p.y);
for (let i = 1; i <= trailLength; i++) {
const oldX = p.x - p.vx * i;
const oldY = p.y - p.vy * i;
const alpha = Math.min(1, i / trailLength * 0.6);
ctx.lineTo(oldX, oldY);
}
// Draw particle
ctx.lineTo(p.x, p.y);
ctx.strokeStyle = `hsl(0, 0%, ${brightness}%)`;
ctx.lineWidth = p.size * 0.5;
ctx.stroke();
}
}
function animate() {
updateField();
updateParticles();
draw();
requestAnimationFrame(animate);
}
initField();
initParticles();
animate();
</script>
</body>
</html>