flowing-fractured-whispers-.../index.html

193 lines
No EOL
6.1 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;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: center;
}
canvas {
display: block;
}
.attribution {
color: #666;
font-family: monospace;
font-size: 10px;
margin-bottom: 10px;
letter-spacing: 1px;
}
</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');
// Set canvas to full window size
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Organism parameters
const motion = 0.5;
const density = 0.5;
const complexity = 0.5;
const connectedness = 0.5;
const lifespan = 0.5;
// Pulse parameters
const avgPulse = 1.1;
const minPulse = 1.0;
const maxPulse = 1.2;
// Tone parameters
const dryness = 0.9;
const curiosity = 0.1;
// Flow field settings
const fieldSize = 50;
const fieldWidth = Math.floor(canvas.width / fieldSize);
const fieldHeight = Math.floor(canvas.height / fieldSize);
const noiseScale = 0.05;
const timeScale = 0.002;
// Particle settings
const particleCount = Math.floor(500 + density * 1000);
const particles = [];
const maxAge = 100;
// 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,
vx: 0,
vy: 0,
age: Math.random() * maxAge,
color: `hsl(0, 0%, ${80 + Math.random() * 20}%)`,
size: 1 + Math.random() * 2,
pulse: 1 + Math.random() * 0.2
});
}
}
// Initialize flow field
const flowField = Array(fieldHeight).fill().map(() =>
Array(fieldWidth).fill()
);
function updateFlowField() {
const time = performance.now() * timeScale;
for (let y = 0; y < fieldHeight; y++) {
for (let x = 0; x < fieldWidth; x++) {
const nx = x * noiseScale;
const ny = y * noiseScale;
// Generate smooth noise
const angle = (
noise(nx + time * 0.1, ny) * Math.PI * 2 +
noise(nx * 2 + time * 0.3, ny * 2) * Math.PI * 0.5 +
time * 0.05
);
flowField[y][x] = {
angle: angle,
strength: 0.5 + noise(nx * 3, ny * 3) * 0.5
};
}
}
}
// Simple 2D noise function
function noise(x, y) {
// Using a simple pseudo-random function
return (Math.sin(x * 12.9898 + y * 78.233) * 43758.5453) % 1;
}
// Update particles based on flow field
function updateParticles() {
const pulseScale = avgPulse + (Math.sin(performance.now() * 0.001) * 0.1);
for (const p of particles) {
p.age += 1;
if (p.age > maxAge) {
p.x = Math.random() * canvas.width;
p.y = Math.random() * canvas.height;
p.age = 0;
}
const fieldX = Math.floor(p.x / fieldSize);
const fieldY = Math.floor(p.y / fieldSize);
if (fieldX >= 0 && fieldX < fieldWidth && fieldY >= 0 && fieldY < fieldHeight) {
const field = flowField[fieldY][fieldX];
const strength = field.strength * pulseScale;
p.vx += Math.cos(field.angle) * 0.1 * strength * motion;
p.vy += Math.sin(field.angle) * 0.1 * strength * motion;
// Add some randomness based on complexity
p.vx += (Math.random() - 0.5) * 0.02 * complexity;
p.vy += (Math.random() - 0.5) * 0.02 * complexity;
}
p.x += p.vx;
p.y += p.vy;
// 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;
}
}
// Draw everything
function draw() {
// Fade the canvas slightly to create trails
ctx.fillStyle = 'rgba(10, 10, 10, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw particles
for (const p of particles) {
const alpha = dryness > 0.8 ? 1 - (p.age / maxAge) : 1;
ctx.strokeStyle = `rgba(200, 200, 200, ${alpha * 0.7})`;
ctx.lineWidth = p.size * (0.5 + 0.5 * (1 - p.age / maxAge));
ctx.beginPath();
ctx.moveTo(p.x, p.y);
ctx.lineTo(p.x + p.vx * 5, p.y + p.vy * 5);
ctx.stroke();
}
}
// Animation loop
function animate() {
updateFlowField();
updateParticles();
draw();
requestAnimationFrame(animate);
}
initParticles();
animate();
</script>
</body>
</html>