fluids-of-chance-geometry-0mrj/index.html

215 lines
No EOL
6.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Neurameba Flow Field</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
}
canvas {
display: block;
}
#attribution {
position: fixed;
bottom: 10px;
right: 10px;
color: #444;
font-size: 10px;
text-shadow: 0 0 5px #222;
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 motion = 0.5;
const density = 0.5;
const complexity = 0.5;
const connectedness = 0.5;
const lifespan = 0.5;
// Tone parameters
const dryness = 0.9;
// Particle system
const particleCount = Math.floor(200 + density * 800);
const particles = [];
const maxSpeed = 2 + motion * 3;
const minSpeed = 0.3 + motion * 0.5;
// Flow field
const gridSize = 30;
const cols = Math.ceil(canvas.width / gridSize);
const rows = Math.ceil(canvas.height / gridSize);
const field = [];
// Initialize flow field
function initField() {
field.length = 0;
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
const angle = Math.random() * Math.PI * 2;
const strength = 0.5 + Math.random() * 0.5;
field.push({ angle, strength });
}
}
}
// 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,
size: 1 + Math.random() * 2,
speed: minSpeed + (maxSpeed - minSpeed) * Math.random(),
angle: Math.random() * Math.PI * 2,
prevX: 0,
prevY: 0,
lifespan: 0,
maxLifespan: 100 + Math.random() * 200,
color: `rgba(255, 255, 255, ${0.5 + Math.random() * 0.5})`
});
}
}
// Update flow field based on noise
function updateField() {
const time = performance.now() * 0.001;
for (let y = 0; y < rows; y++) {
for (let x = 0; x < cols; x++) {
const idx = y * cols + x;
const nx = x * 0.05;
const ny = y * 0.05;
const angle = noise(nx * complexity + time, ny * complexity + time) * Math.PI * 2;
const strength = 0.5 + noise(nx * 0.2 + time * 0.3, ny * 0.2 + time * 0.3) * 0.5;
field[idx] = { angle, strength };
}
}
}
// Noise function
function noise(x, y) {
let n = x + y * 57;
n = Math.sin(n) * 43758.5453;
return n - Math.floor(n);
}
// Update particles
function updateParticles() {
particles.forEach(p => {
// Save previous position
p.prevX = p.x;
p.prevY = p.y;
// Get field value
const col = Math.floor(p.x / gridSize);
const row = Math.floor(p.y / gridSize);
if (col >= 0 && col < cols && row >= 0 && row < rows) {
const idx = row * cols + col;
const fieldValue = field[idx];
// Update angle based on flow field
p.angle = fieldValue.angle + (Math.random() - 0.5) * (1 - connectedness) * 0.5;
p.speed = minSpeed + (maxSpeed - minSpeed) * fieldValue.strength * (0.8 + motion * 0.2);
}
// Move particle
p.x += Math.cos(p.angle) * p.speed;
p.y += Math.sin(p.angle) * p.speed;
// Bounce off edges
if (p.x < 0) {
p.x = 0;
p.angle = Math.PI - p.angle;
} else if (p.x > canvas.width) {
p.x = canvas.width;
p.angle = Math.PI - p.angle;
}
if (p.y < 0) {
p.y = 0;
p.angle = -p.angle;
} else if (p.y > canvas.height) {
p.y = canvas.height;
p.angle = -p.angle;
}
// Update lifespan
p.lifespan++;
if (p.lifespan > p.maxLifespan * lifespan + 100 * (1 - lifespan)) {
p.x = Math.random() * canvas.width;
p.y = Math.random() * canvas.height;
p.lifespan = 0;
p.maxLifespan = 100 + Math.random() * 200;
}
});
}
// Draw particles
function drawParticles() {
ctx.strokeStyle = dryness > 0.8 ? 'rgba(255, 255, 255, 0.1)' : 'rgba(255, 100, 100, 0.1)';
ctx.lineWidth = 1;
particles.forEach(p => {
// Draw lines from previous position
if (p.prevX !== p.x || p.prevY !== p.y) {
ctx.beginPath();
ctx.moveTo(p.prevX, p.prevY);
ctx.lineTo(p.x, p.y);
ctx.stroke();
}
// Draw particle
ctx.beginPath();
ctx.arc(p.x, p.y, p.size * (0.5 + (p.lifespan / p.maxLifespan) * 0.5), 0, Math.PI * 2);
ctx.fillStyle = p.color;
ctx.fill();
});
}
// Animation loop
let lastTime = 0;
function animate(time) {
const deltaTime = time - lastTime;
lastTime = time;
// Clear with semi-transparent background
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
updateField();
updateParticles();
drawParticles();
requestAnimationFrame(animate);
}
// Start animation
initField();
initParticles();
requestAnimationFrame(animate);
</script>
</body>
</html>