175 lines
No EOL
5.4 KiB
HTML
175 lines
No EOL
5.4 KiB
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 Organism</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a0a;
|
|
color: #f0f0f0;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
#attribution {
|
|
position: absolute;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
font-size: 10px;
|
|
opacity: 0.6;
|
|
}
|
|
</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 settings
|
|
const FIELD_SIZE = 30;
|
|
const PARTICLE_COUNT = 150;
|
|
const PARTICLE_SIZE = 1.2;
|
|
const TRAIL_LENGTH = 80;
|
|
const MAX_SPEED = 0.25;
|
|
|
|
// Create flow field
|
|
const field = [];
|
|
const fieldWidth = Math.ceil(canvas.width / FIELD_SIZE);
|
|
const fieldHeight = Math.ceil(canvas.height / FIELD_SIZE);
|
|
|
|
// Initialize particles
|
|
const particles = Array(PARTICLE_COUNT).fill().map(() => ({
|
|
x: Math.random() * canvas.width,
|
|
y: Math.random() * canvas.height,
|
|
prevX: 0,
|
|
prevY: 0,
|
|
speed: 0.1 + Math.random() * MAX_SPEED,
|
|
angle: Math.random() * Math.PI * 2,
|
|
history: [],
|
|
color: `hsl(${Math.random() * 360}, 30%, 80%)`,
|
|
size: PARTICLE_SIZE * (0.8 + Math.random() * 0.4)
|
|
}));
|
|
|
|
// Generate Perlin-like noise field
|
|
function generateField() {
|
|
for (let y = 0; y < fieldHeight; y++) {
|
|
field[y] = [];
|
|
for (let x = 0; x < fieldWidth; x++) {
|
|
const nx = x / fieldWidth;
|
|
const ny = y / fieldHeight;
|
|
const angle = (Math.sin(nx * 10) * Math.cos(ny * 8) * Math.PI * 2) % (Math.PI * 2);
|
|
field[y][x] = angle;
|
|
}
|
|
}
|
|
}
|
|
|
|
function getFieldAngle(x, y) {
|
|
const fx = x / FIELD_SIZE;
|
|
const fy = y / FIELD_SIZE;
|
|
const x1 = Math.floor(fx);
|
|
const y1 = Math.floor(fy);
|
|
const x2 = (x1 + 1) % fieldWidth;
|
|
const y2 = (y1 + 1) % fieldHeight;
|
|
|
|
const sx = fx - x1;
|
|
const sy = fy - y1;
|
|
|
|
const n1 = field[y1][x1];
|
|
const n2 = field[y1][x2];
|
|
const ix1 = n1 + sx * (n2 - n1);
|
|
|
|
const n3 = field[y2][x1];
|
|
const n4 = field[y2][x2];
|
|
const ix2 = n3 + sx * (n4 - n3);
|
|
|
|
return ix1 + sy * (ix2 - ix1);
|
|
}
|
|
|
|
function updateParticles() {
|
|
particles.forEach(p => {
|
|
// Get field angle
|
|
const angle = getFieldAngle(p.x, p.y);
|
|
|
|
// Calculate attraction to center (dryness)
|
|
const centerX = canvas.width / 2;
|
|
const centerY = canvas.height / 2;
|
|
const dx = centerX - p.x;
|
|
const dy = centerY - p.y;
|
|
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
const force = Math.min(0.05, 1 / (dist + 1));
|
|
|
|
// Update particle direction
|
|
p.angle = angle + (force * 0.3);
|
|
|
|
// Move particle
|
|
p.prevX = p.x;
|
|
p.prevY = p.y;
|
|
p.x += Math.cos(p.angle) * p.speed;
|
|
p.y += Math.sin(p.angle) * p.speed;
|
|
|
|
// 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;
|
|
|
|
// Add to history
|
|
p.history.push({x: p.x, y: p.y});
|
|
if (p.history.length > TRAIL_LENGTH) {
|
|
p.history.shift();
|
|
}
|
|
});
|
|
}
|
|
|
|
function drawParticles() {
|
|
ctx.globalCompositeOperation = 'lighter';
|
|
|
|
particles.forEach(p => {
|
|
// Draw trail
|
|
if (p.history.length > 1) {
|
|
ctx.beginPath();
|
|
ctx.moveTo(p.prevX, p.prevY);
|
|
p.history.forEach(point => {
|
|
ctx.lineTo(point.x, point.y);
|
|
});
|
|
ctx.strokeStyle = p.color;
|
|
ctx.lineWidth = p.size * 0.8;
|
|
ctx.stroke();
|
|
}
|
|
|
|
// Draw particle
|
|
ctx.beginPath();
|
|
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
|
ctx.fillStyle = p.color;
|
|
ctx.fill();
|
|
});
|
|
|
|
ctx.globalCompositeOperation = 'source-over';
|
|
}
|
|
|
|
function animate() {
|
|
// Clear with fade effect (low energy/dryness)
|
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.03)';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
generateField();
|
|
updateParticles();
|
|
drawParticles();
|
|
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |