150 lines
No EOL
5.1 KiB
HTML
150 lines
No EOL
5.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Generative Flow Field</title>
|
|
<style>
|
|
body, html {
|
|
margin: 0;
|
|
padding: 0;
|
|
overflow: hidden;
|
|
background: #121212;
|
|
font-family: monospace;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: fixed;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
color: #888;
|
|
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');
|
|
|
|
function resizeCanvas() {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
}
|
|
|
|
window.addEventListener('resize', resizeCanvas);
|
|
resizeCanvas();
|
|
|
|
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.3 },
|
|
tone: { dryness: 0.8, playfulness: 0.1 }
|
|
};
|
|
|
|
const particles = [];
|
|
const particleCount = Math.floor(params.density * 500) + 100;
|
|
|
|
function getPulse() {
|
|
return params.pulse.avg + (Math.random() * (params.pulse.max - params.pulse.min) - (params.pulse.max - params.pulse.avg));
|
|
}
|
|
|
|
for (let i = 0; i < particleCount; i++) {
|
|
particles.push({
|
|
x: Math.random() * canvas.width,
|
|
y: Math.random() * canvas.height,
|
|
vx: 0,
|
|
vy: 0,
|
|
size: Math.random() * 2 + 1,
|
|
opacity: Math.random() * 0.5 + 0.1,
|
|
hue: Math.random() * 360,
|
|
speed: getPulse(),
|
|
lifetime: 0,
|
|
maxLifetime: 100 + Math.random() * 200,
|
|
pulse: getPulse(),
|
|
targetX: Math.random() * canvas.width,
|
|
targetY: Math.random() * canvas.height
|
|
});
|
|
}
|
|
|
|
function drawParticle(particle) {
|
|
ctx.beginPath();
|
|
ctx.arc(particle.x, particle.y, particle.size * (1 - particle.lifetime / particle.maxLifetime), 0, Math.PI * 2);
|
|
ctx.fillStyle = `hsla(${particle.hue}, 30%, ${80 - particle.opacity * 30}%, ${particle.opacity * (1 - particle.lifetime / particle.maxLifetime)})`;
|
|
ctx.fill();
|
|
}
|
|
|
|
function updateParticle(particle, index) {
|
|
// Fade in/out based on pulse
|
|
const pulse = particle.pulse;
|
|
const motionFactor = params.motion * 0.5 + 0.5;
|
|
|
|
// Create flow field effect with some disturbance
|
|
const centerX = canvas.width / 2;
|
|
const centerY = canvas.height / 2;
|
|
const distToCenter = Math.sqrt(Math.pow(particle.x - centerX, 2) + Math.pow(particle.y - centerY, 2));
|
|
const centerFactor = 1 - Math.min(distToCenter / Math.max(centerX, centerY), 1);
|
|
|
|
// Base flow toward center
|
|
const fx = (centerX - particle.x) * 0.0005 * centerFactor;
|
|
const fy = (centerY - particle.y) * 0.0005 * centerFactor;
|
|
|
|
// Add some randomness
|
|
particle.vx += (fx + (Math.random() - 0.5) * motionFactor * 0.1) * pulse;
|
|
particle.vy += (fy + (Math.random() - 0.5) * motionFactor * 0.1) * pulse;
|
|
|
|
// Apply drag
|
|
particle.vx *= 0.95;
|
|
particle.vy *= 0.95;
|
|
|
|
// Update position
|
|
particle.x += particle.vx;
|
|
particle.y += particle.vy;
|
|
|
|
// Bounce off edges with some energy loss
|
|
if (particle.x < 0 || particle.x > canvas.width) {
|
|
particle.vx *= -0.8;
|
|
particle.x = Math.max(0, Math.min(canvas.width, particle.x));
|
|
}
|
|
if (particle.y < 0 || particle.y > canvas.height) {
|
|
particle.vy *= -0.8;
|
|
particle.y = Math.max(0, Math.min(canvas.height, particle.y));
|
|
}
|
|
|
|
// Update lifetime
|
|
particle.lifetime++;
|
|
if (particle.lifetime > particle.maxLifetime) {
|
|
particle.lifetime = 0;
|
|
particle.x = Math.random() * canvas.width;
|
|
particle.y = Math.random() * canvas.height;
|
|
particle.targetX = Math.random() * canvas.width;
|
|
particle.targetY = Math.random() * canvas.height;
|
|
}
|
|
}
|
|
|
|
function animate() {
|
|
// Clear with semi-transparent background to create trails
|
|
ctx.fillStyle = 'rgba(18, 18, 18, 0.05)';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
// Update and draw all particles
|
|
particles.forEach((particle, index) => {
|
|
updateParticle(particle, index);
|
|
drawParticle(particle);
|
|
});
|
|
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |