birth: Flowing tendrils in twilight
This commit is contained in:
parent
c4e0c8c085
commit
505a7d2be1
1 changed files with 227 additions and 0 deletions
227
index.html
Normal file
227
index.html
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
<!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;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 20px;
|
||||
color: #555;
|
||||
font-size: 10px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
}
|
||||
</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');
|
||||
|
||||
// Set canvas to full window size
|
||||
function resizeCanvas() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
window.addEventListener('resize', resizeCanvas);
|
||||
resizeCanvas();
|
||||
|
||||
// Parameters
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
pulse: { avg: 1.11, min: 0.95, max: 1.30 },
|
||||
tone: { anger: 0.00, sadness: 0.00, curiosity: 0.10, dryness: 0.90, playfulness: 0.00, tension: 0.00 }
|
||||
};
|
||||
|
||||
// Flow field settings
|
||||
const field = {
|
||||
size: 20,
|
||||
influence: 5,
|
||||
flow: 0.05,
|
||||
decay: 0.95,
|
||||
nodes: []
|
||||
};
|
||||
|
||||
// Particle system
|
||||
const particles = [];
|
||||
const particleCount = Math.floor(300 * params.density);
|
||||
|
||||
// Initialize flow field
|
||||
function initField() {
|
||||
for (let y = 0; y < canvas.height; y += field.size) {
|
||||
for (let x = 0; x < canvas.width; x += field.size) {
|
||||
const angle = Math.random() * Math.PI * 2;
|
||||
const strength = 1 + Math.random() * 0.5;
|
||||
field.nodes.push({
|
||||
x: x,
|
||||
y: y,
|
||||
angle: angle,
|
||||
strength: strength,
|
||||
originalAngle: angle
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create particles with lifespans
|
||||
function initParticles() {
|
||||
for (let i = 0; i < particleCount; i++) {
|
||||
const p = {
|
||||
x: Math.random() * canvas.width,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: 0,
|
||||
vy: 0,
|
||||
life: 0,
|
||||
maxLife: 100 + Math.random() * 200,
|
||||
trail: [],
|
||||
size: 1 + Math.random() * 2 * params.complexity,
|
||||
color: `hsl(0, 0%, ${90 + Math.random() * 10}%)`
|
||||
};
|
||||
particles.push(p);
|
||||
}
|
||||
}
|
||||
|
||||
// Update flow field
|
||||
function updateField() {
|
||||
field.nodes.forEach(node => {
|
||||
// Slow drift over time
|
||||
node.angle += (Math.random() - 0.5) * 0.02 * params.motion;
|
||||
node.angle = (node.angle + Math.PI * 2) % (Math.PI * 2);
|
||||
|
||||
// Slight decay
|
||||
node.strength = Math.max(0.5, node.strength * 0.995);
|
||||
});
|
||||
}
|
||||
|
||||
// Update particles
|
||||
function updateParticles() {
|
||||
particles.forEach(p => {
|
||||
p.life += 1;
|
||||
|
||||
// Find nearest field node
|
||||
let nearest = null;
|
||||
let minDist = Infinity;
|
||||
for (const node of field.nodes) {
|
||||
const dist = Math.hypot(p.x - node.x, p.y - node.y);
|
||||
if (dist < minDist) {
|
||||
minDist = dist;
|
||||
nearest = node;
|
||||
}
|
||||
}
|
||||
|
||||
// Move toward field direction
|
||||
if (nearest && minDist < field.influence) {
|
||||
const angleDiff = ((nearest.angle - Math.atan2(p.y - nearest.y, p.x - nearest.x)) + Math.PI) % (Math.PI * 2) - Math.PI;
|
||||
p.vx += Math.cos(nearest.angle) * nearest.strength * 0.01 * params.motion;
|
||||
p.vy += Math.sin(nearest.angle) * nearest.strength * 0.01 * params.motion;
|
||||
}
|
||||
|
||||
// Apply resistance
|
||||
p.vx *= 0.95;
|
||||
p.vy *= 0.95;
|
||||
|
||||
// Update position
|
||||
p.x += p.vx;
|
||||
p.y += p.vy;
|
||||
|
||||
// Bounce at edges
|
||||
if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
|
||||
if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
|
||||
|
||||
// Trail
|
||||
p.trail.push({x: p.x, y: p.y});
|
||||
if (p.trail.length > 20) p.trail.shift();
|
||||
|
||||
// Fade and die
|
||||
if (p.life > p.maxLife) {
|
||||
p.maxLife = 0;
|
||||
}
|
||||
});
|
||||
|
||||
// Remove dead particles
|
||||
for (let i = particles.length - 1; i >= 0; i--) {
|
||||
if (particles[i].maxLife <= 0) {
|
||||
particles.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Add new particles to maintain density
|
||||
while (particles.length < particleCount) {
|
||||
initParticles();
|
||||
}
|
||||
}
|
||||
|
||||
// Draw
|
||||
function draw() {
|
||||
// Fade background slightly
|
||||
ctx.fillStyle = 'rgba(10, 10, 10, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Draw particles
|
||||
particles.forEach(p => {
|
||||
if (p.trail.length > 1) {
|
||||
// Draw trail
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(p.trail[0].x, p.trail[0].y);
|
||||
for (let i = 1; i < p.trail.length; i++) {
|
||||
const alpha = i / p.trail.length * 0.8;
|
||||
ctx.strokeStyle = `rgba(255, 255, 255, ${alpha})`;
|
||||
ctx.lineTo(p.trail[i].x, p.trail[i].y);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
// Draw particle
|
||||
ctx.beginPath();
|
||||
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
||||
ctx.fillStyle = p.color;
|
||||
ctx.fill();
|
||||
});
|
||||
|
||||
// Draw field nodes occasionally
|
||||
if (Math.random() < 0.02) {
|
||||
const node = field.nodes[Math.floor(Math.random() * field.nodes.length)];
|
||||
ctx.beginPath();
|
||||
ctx.arc(node.x, node.y, 2, 0, Math.PI * 2);
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
// Animation loop
|
||||
function animate() {
|
||||
updateField();
|
||||
updateParticles();
|
||||
draw();
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
// Start
|
||||
initField();
|
||||
initParticles();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue