birth: Flowing Particles in Emptiness
This commit is contained in:
parent
41842fff29
commit
46e5d090a2
1 changed files with 113 additions and 0 deletions
113
index.html
Normal file
113
index.html
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
```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</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
font-family: monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
color: #fff;
|
||||
font-size: 10px;
|
||||
mix-blend-mode: difference;
|
||||
}
|
||||
</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 resize() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
window.addEventListener('resize', resize);
|
||||
resize();
|
||||
|
||||
// Parameters
|
||||
const motion = 0.5;
|
||||
const density = 0.5;
|
||||
const complexity = 0.5;
|
||||
const connectedness = 0.5;
|
||||
const lifespan = 0.5;
|
||||
|
||||
// Flow field parameters
|
||||
const particleCount = 200 * density;
|
||||
const particles = Array(particleCount).fill().map(() => ({
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: 0,
|
||||
vy: 0,
|
||||
size: 2 + Math.random() * 3 * complexity,
|
||||
life: Math.random() * 100 * lifespan
|
||||
}));
|
||||
|
||||
const timeScale = 0.001 + motion * 0.01;
|
||||
const colorVariation = dryness * 0.3;
|
||||
|
||||
function draw() {
|
||||
// Clear with semi-transparent to create trails
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Update particles
|
||||
particles.forEach(p => {
|
||||
// Flow field based on noise
|
||||
const nx = p.x / canvas.width * 5;
|
||||
const ny = p.y / canvas.height * 5;
|
||||
const angle = Math.sin(nx * 10 + performance.now() * timeScale * 0.1) *
|
||||
Math.cos(ny * 10 + performance.now() * timeScale * 0.1);
|
||||
|
||||
p.vx = Math.cos(angle) * motion * 2;
|
||||
p.vy = Math.sin(angle) * motion * 2;
|
||||
|
||||
p.x += p.vx;
|
||||
p.y += p.vy;
|
||||
|
||||
// Wrap around edges
|
||||
if (p.x < 0) p.x = canvas.width;
|
||||
if (p.x > canvas.width) p.x = 0;
|
||||
if (p.y < 0) p.y = canvas.height;
|
||||
if (p.y > canvas.height) p.y = 0;
|
||||
|
||||
// Trail effect with life
|
||||
const alpha = Math.min(1, p.life / 100) * (1 - colorVariation);
|
||||
ctx.fillStyle = `rgba(255, 255, 255, ${alpha})`;
|
||||
ctx.beginPath();
|
||||
ctx.arc(p.x, p.y, p.size * (0.5 + Math.random() * 0.5 * complexity), 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
|
||||
p.life--;
|
||||
if (p.life <= 0) {
|
||||
p.x = Math.random() * canvas.width;
|
||||
p.y = Math.random() * canvas.height;
|
||||
p.life = 100;
|
||||
}
|
||||
});
|
||||
|
||||
requestAnimationFrame(draw);
|
||||
}
|
||||
|
||||
draw();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
Loading…
Add table
Reference in a new issue