birth: Flowing Monochrome Constellations
This commit is contained in:
parent
0d7fdcdf48
commit
e1d7145618
1 changed files with 185 additions and 0 deletions
185
index.html
Normal file
185
index.html
Normal file
|
|
@ -0,0 +1,185 @@
|
||||||
|
<!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; }
|
||||||
|
canvas { display: block; }
|
||||||
|
.attribution { position: absolute; bottom: 10px; right: 10px; color: #444; font-family: monospace; font-size: 10px; }
|
||||||
|
</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 resizeCanvas() {
|
||||||
|
canvas.width = window.innerWidth;
|
||||||
|
canvas.height = window.innerHeight;
|
||||||
|
}
|
||||||
|
window.addEventListener('resize', resizeCanvas);
|
||||||
|
resizeCanvas();
|
||||||
|
|
||||||
|
// Organism parameters
|
||||||
|
const params = {
|
||||||
|
motion: 0.5,
|
||||||
|
density: 0.5,
|
||||||
|
complexity: 0.5,
|
||||||
|
connectedness: 0.5,
|
||||||
|
lifespan: 0.5,
|
||||||
|
pulse: { avg: 1.03, min: 0.8, max: 1.2 },
|
||||||
|
tone: { anger: 0.0, sadness: 0.0, curiosity: 0.1, dryness: 0.9, playfulness: 0.0, tension: 0.0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Flow field parameters
|
||||||
|
const particleCount = Math.floor(100 + params.density * 200);
|
||||||
|
const particles = [];
|
||||||
|
const gridSize = 20;
|
||||||
|
const flowField = [];
|
||||||
|
const flowStrength = 0.1 + params.motion * 0.2;
|
||||||
|
const noiseScale = 0.05;
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
speed: 0.5 + Math.random() * 1.5,
|
||||||
|
size: 1 + Math.random() * 2,
|
||||||
|
hue: 0,
|
||||||
|
life: 0,
|
||||||
|
maxLife: 100 + Math.random() * 200
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
initParticles();
|
||||||
|
|
||||||
|
// Initialize flow field
|
||||||
|
function initFlowField() {
|
||||||
|
flowField.length = 0;
|
||||||
|
for (let y = 0; y < canvas.height / gridSize; y++) {
|
||||||
|
for (let x = 0; x < canvas.width / gridSize; x++) {
|
||||||
|
const angle = Math.random() * Math.PI * 2;
|
||||||
|
flowField.push({
|
||||||
|
vx: Math.cos(angle) * flowStrength,
|
||||||
|
vy: Math.sin(angle) * flowStrength
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
initFlowField();
|
||||||
|
|
||||||
|
// Noise-based flow field
|
||||||
|
function updateFlowField(time) {
|
||||||
|
flowField.forEach((cell, i) => {
|
||||||
|
const x = (i % (canvas.width / gridSize)) * gridSize;
|
||||||
|
const y = Math.floor(i / (canvas.width / gridSize)) * gridSize;
|
||||||
|
const n = noise(x * noiseScale, y * noiseScale, time * 0.0005);
|
||||||
|
const angle = n * Math.PI * 8;
|
||||||
|
cell.vx = Math.cos(angle) * flowStrength;
|
||||||
|
cell.vy = Math.sin(angle) * flowStrength;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Particle movement
|
||||||
|
function updateParticles(time) {
|
||||||
|
particles.forEach(particle => {
|
||||||
|
// Get flow field value
|
||||||
|
const gridX = Math.floor(particle.x / gridSize);
|
||||||
|
const gridY = Math.floor(particle.y / gridSize);
|
||||||
|
const index = gridY * (canvas.width / gridSize) + gridX;
|
||||||
|
|
||||||
|
if (index >= 0 && index < flowField.length) {
|
||||||
|
// Blend with current velocity
|
||||||
|
const currentVx = particle.x - (particle.prevX || particle.x);
|
||||||
|
const currentVy = particle.y - (particle.prevY || particle.y);
|
||||||
|
|
||||||
|
particle.prevX = particle.x;
|
||||||
|
particle.prevY = particle.y;
|
||||||
|
|
||||||
|
particle.x += (currentVx + flowField[index].vx * particle.speed) * 0.5;
|
||||||
|
particle.y += (currentVy + flowField[index].vy * particle.speed) * 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrap around edges
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Update life
|
||||||
|
particle.life++;
|
||||||
|
if (particle.life > particle.maxLife) {
|
||||||
|
particle.x = Math.random() * canvas.width;
|
||||||
|
particle.y = Math.random() * canvas.height;
|
||||||
|
particle.life = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drawing
|
||||||
|
function draw(time) {
|
||||||
|
// Fade background
|
||||||
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.02)';
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
// Draw particles
|
||||||
|
ctx.lineCap = 'round';
|
||||||
|
particles.forEach(particle => {
|
||||||
|
const t = particle.life / particle.maxLife;
|
||||||
|
const pulse = params.pulse.avg + Math.sin(time * 0.001) * 0.1;
|
||||||
|
|
||||||
|
ctx.lineWidth = particle.size * (0.3 + t * 0.7) * pulse;
|
||||||
|
ctx.strokeStyle = `hsl(0, 0%, ${80 + Math.sin(t * Math.PI * 2) * 20}%)`;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(particle.prevX || particle.x, particle.prevY || particle.y);
|
||||||
|
ctx.lineTo(particle.x, particle.y);
|
||||||
|
ctx.stroke();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Draw flow field (subtle)
|
||||||
|
if (time % 20 < 1) {
|
||||||
|
ctx.strokeStyle = 'rgba(255,255,255,0.02)';
|
||||||
|
ctx.lineWidth = 0.5;
|
||||||
|
|
||||||
|
for (let y = 0; y < canvas.height; y += 20) {
|
||||||
|
for (let x = 0; x < canvas.width; x += 20) {
|
||||||
|
const index = (Math.floor(y/gridSize) * (canvas.width/gridSize)) + Math.floor(x/gridSize);
|
||||||
|
if (index < flowField.length) {
|
||||||
|
const len = Math.sqrt(flowField[index].vx ** 2 + flowField[index].vy ** 2) * 2;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(x, y);
|
||||||
|
ctx.lineTo(x + flowField[index].vx * len, y + flowField[index].vy * len);
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function animate(time) {
|
||||||
|
updateFlowField(time);
|
||||||
|
updateParticles(time);
|
||||||
|
draw(time);
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
animate(0);
|
||||||
|
|
||||||
|
// Handle window focus/blur to pause/resume
|
||||||
|
document.addEventListener('visibilitychange', () => {
|
||||||
|
if (document.hidden) {
|
||||||
|
// Pause
|
||||||
|
} else {
|
||||||
|
// Resume
|
||||||
|
initParticles();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue