birth: Organic currents in twilight
This commit is contained in:
parent
3bac63b1b6
commit
04c614e810
1 changed files with 213 additions and 0 deletions
213
index.html
Normal file
213
index.html
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Flow Field Organism</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
color: #444;
|
||||
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();
|
||||
|
||||
// Flow field parameters
|
||||
const particleCount = 140;
|
||||
const particles = [];
|
||||
const flowResolution = 20;
|
||||
const field = new Array(flowResolution * flowResolution);
|
||||
const fieldStrength = 0.482;
|
||||
const decayRate = 0.97;
|
||||
const pulse = { current: 0.6, target: 0.6, speed: 0.02 };
|
||||
|
||||
// Tone mapping
|
||||
const palette = {
|
||||
background: '#0a0a0a',
|
||||
particles: '#ffffff',
|
||||
flowLines: '#333333'
|
||||
};
|
||||
|
||||
class Particle {
|
||||
constructor() {
|
||||
this.reset();
|
||||
this.size = 0.5 + Math.random() * 0.5;
|
||||
this.speed = 0.5 + Math.random() * 2;
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.pos = {
|
||||
x: Math.random(),
|
||||
y: Math.random()
|
||||
};
|
||||
this.vel = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
this.life = 1;
|
||||
this.trail = [];
|
||||
}
|
||||
|
||||
update() {
|
||||
const gridX = Math.floor(this.pos.x * flowResolution) % flowResolution;
|
||||
const gridY = Math.floor(this.pos.y * flowResolution) % flowResolution;
|
||||
const index = gridY * flowResolution + gridX;
|
||||
const flow = field[index];
|
||||
|
||||
// Apply flow field with some randomness
|
||||
this.vel.x = (flow.x * fieldStrength) + (Math.random() - 0.5) * 0.3;
|
||||
this.vel.y = (flow.y * fieldStrength) + (Math.random() - 0.5) * 0.3;
|
||||
|
||||
// Update position with speed factor
|
||||
this.pos.x += this.vel.x * this.speed * pulse.current;
|
||||
this.pos.y += this.vel.y * this.speed * pulse.current;
|
||||
|
||||
// Boundary check
|
||||
if (this.pos.x < 0 || this.pos.x > 1 || this.pos.y < 0 || this.pos.y > 1) {
|
||||
this.reset();
|
||||
}
|
||||
|
||||
// Update life
|
||||
this.life *= decayRate;
|
||||
}
|
||||
|
||||
draw() {
|
||||
if (this.life < 0.01) return;
|
||||
|
||||
// Trail
|
||||
this.trail.push({...this.pos, life: this.life});
|
||||
if (this.trail.length > 20) this.trail.shift();
|
||||
|
||||
// Main particle
|
||||
ctx.beginPath();
|
||||
ctx.arc(
|
||||
this.pos.x * canvas.width,
|
||||
this.pos.y * canvas.height,
|
||||
this.size * 3 * this.life,
|
||||
0,
|
||||
Math.PI * 2
|
||||
);
|
||||
ctx.fillStyle = `rgba(255, 255, 255, ${this.life * 0.8})`;
|
||||
ctx.fill();
|
||||
|
||||
// Trail
|
||||
ctx.beginPath();
|
||||
this.trail.forEach((point, i) => {
|
||||
const alpha = point.life * (i / this.trail.length) * 0.5;
|
||||
ctx.lineWidth = this.size * 2 * alpha;
|
||||
ctx.moveTo(point.x * canvas.width, point.y * canvas.height);
|
||||
const next = this.trail[i + 1];
|
||||
if (next) {
|
||||
ctx.lineTo(next.x * canvas.width, next.y * canvas.height);
|
||||
}
|
||||
});
|
||||
ctx.strokeStyle = `rgba(255, 255, 255, ${this.life * 0.3})`;
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
function initFlowField() {
|
||||
for (let i = 0; i < field.length; i++) {
|
||||
field[i] = {
|
||||
x: Math.random() * 2 - 1,
|
||||
y: Math.random() * 2 - 1
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function updateFlowField() {
|
||||
// Simulate fluid dynamics - slowly converge to organized flow
|
||||
for (let i = 0; i < field.length; i++) {
|
||||
const x = i % flowResolution;
|
||||
const y = Math.floor(i / flowResolution);
|
||||
|
||||
// Neighbor influence
|
||||
let avgX = 0, avgY = 0;
|
||||
let count = 0;
|
||||
|
||||
for (let nx = -1; nx <= 1; nx++) {
|
||||
for (let ny = -1; ny <= 1; ny++) {
|
||||
if (nx === 0 && ny === 0) continue;
|
||||
const nx2 = (x + nx + flowResolution) % flowResolution;
|
||||
const ny2 = (y + ny + flowResolution) % flowResolution;
|
||||
const ni = ny2 * flowResolution + nx2;
|
||||
|
||||
avgX += field[ni].x;
|
||||
avgY += field[ni].y;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
field[i].x = field[i].x * 0.8 + (avgX / count) * 0.2;
|
||||
field[i].y = field[i].y * 0.8 + (avgY / count) * 0.2;
|
||||
}
|
||||
|
||||
// Add some organic variation
|
||||
for (let i = 0; i < field.length * 0.05; i++) {
|
||||
const idx = Math.floor(Math.random() * field.length);
|
||||
field[idx].x += (Math.random() - 0.5) * 0.2;
|
||||
field[idx].y += (Math.random() - 0.5) * 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
function initParticles() {
|
||||
for (let i = 0; i < particleCount; i++) {
|
||||
particles.push(new Particle());
|
||||
}
|
||||
}
|
||||
|
||||
function updatePulse() {
|
||||
if (Math.random() < 0.01) {
|
||||
pulse.target = 0.3 + Math.random() * 1.7;
|
||||
}
|
||||
pulse.current += (pulse.target - pulse.current) * pulse.speed;
|
||||
}
|
||||
|
||||
function animate() {
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
updateFlowField();
|
||||
updatePulse();
|
||||
|
||||
particles.forEach(p => {
|
||||
p.update();
|
||||
p.draw();
|
||||
});
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
initFlowField();
|
||||
initParticles();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue