flows-of-curiosity-f90f/index.html

234 lines
No EOL
7.5 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;
font-family: 'Courier New', monospace;
}
canvas {
display: block;
}
#attribution {
position: fixed;
bottom: 10px;
right: 10px;
color: #555;
font-size: 10px;
text-shadow: 0 0 5px rgba(0,0,0,0.5);
}
</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();
// Organism parameters
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: { avg: 1.07, min: 1.0, max: 1.1 },
tone: { anger: 0.0, sadness: 0.0, curiosity: 0.7, dryness: 0.8, playfulness: 0.3, tension: 0.0 }
};
// Flow field properties
const field = {
cols: Math.floor(canvas.width / 10),
rows: Math.floor(canvas.height / 10),
noiseScale: 0.05,
angleOffset: 0,
strength: 0.5
};
// Particle system properties
const particles = [];
const maxParticles = 500 * params.density;
// Initialize particles
function initParticles() {
particles.length = 0;
for (let i = 0; i < maxParticles; i++) {
particles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
size: Math.random() * 3 + 1,
speed: 0.5 + Math.random() * 0.5,
angle: Math.random() * Math.PI * 2,
trail: [],
maxTrailLength: 10 + Math.floor(params.complexity * 20),
hue: 160 + Math.random() * 40,
saturation: 50 + Math.random() * 30,
lightness: 60 + Math.random() * 20,
life: params.lifespan * 100 + Math.random() * 100,
opacity: params.tone.dryness > 0.7 ? 0.3 + Math.random() * 0.2 : 0.7 + Math.random() * 0.3
});
}
}
initParticles();
// Flow field functions
function getVector(x, y, time) {
// Base angle from noise
let angle = noise.simplex3(x * field.noiseScale,
y * field.noiseScale,
time * 0.01) * Math.PI * 2;
// Add animation pulse
angle += Math.sin(time * params.pulse.avg) * 0.5;
// Add complexity variation
angle += noise.simplex3(x * field.noiseScale * 2,
y * field.noiseScale * 2,
time * 0.005) * 0.3;
return {
x: Math.cos(angle) * field.strength,
y: Math.sin(angle) * field.strength
};
}
// Particle update
function updateParticle(p, time) {
// Get field vector
const v = getVector(p.x, p.y, time);
// Update angle based on field
p.angle = Math.atan2(v.y, v.x);
// Move particle
p.x += v.x * p.speed;
p.y += v.y * 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;
// Update trail
p.trail.push({x: p.x, y: p.y});
if (p.trail.length > p.maxTrailLength) {
p.trail.shift();
}
// Fade out if low lifespan
if (params.lifespan < 0.3) {
p.opacity *= 0.98;
}
}
// Drawing functions
function drawField(time) {
// Reduce field visualization at high complexity
if (params.complexity > 0.7) return;
ctx.strokeStyle = `hsla(180, 50%, 60%, 0.1)`;
ctx.lineWidth = 1;
// Draw a grid of flow vectors
for (let y = 0; y < field.rows; y++) {
for (let x = 0; x < field.cols; x++) {
const px = x * 10;
const py = y * 10;
const v = getVector(px, py, time);
ctx.beginPath();
ctx.moveTo(px, py);
ctx.lineTo(px + v.x * 5, py + v.y * 5);
ctx.stroke();
}
}
}
function drawParticles(time) {
particles.forEach(p => {
// Draw trail
if (p.trail.length > 1) {
ctx.beginPath();
// Fade trail based on particle properties
const trailOpacity = p.opacity * (0.2 + 0.8 * (p.life / 100));
// Color variation based on time
const colorTime = time * 0.01;
const hue = p.hue + Math.sin(colorTime) * 20;
ctx.strokeStyle = `hsla(${hue}, ${p.saturation}%, ${p.lightness}%, ${trailOpacity})`;
ctx.lineWidth = p.size * 0.5;
p.trail.forEach((segment, i) => {
const next = p.trail[i + 1] || segment;
const alpha = i / p.trail.length;
ctx.globalAlpha = trailOpacity * alpha;
ctx.beginPath();
ctx.moveTo(segment.x, segment.y);
ctx.lineTo(next.x, next.y);
ctx.stroke();
});
ctx.globalAlpha = 1;
}
// Draw particle
ctx.beginPath();
const pulseMod = 1 + Math.sin(time * 2) * 0.2 * params.pulse.avg;
const size = p.size * pulseMod;
const opacity = p.opacity * Math.min(1, p.life / 50);
ctx.fillStyle = `hsla(${p.hue}, ${p.saturation}%, ${p.lightness}%, ${opacity})`;
ctx.arc(p.x, p.y, size, 0, Math.PI * 2);
ctx.fill();
});
}
// Animation loop
let time = 0;
function animate() {
// Clear with semi-transparent background for trails
ctx.fillStyle = 'rgba(0, 0, 0, 0.3)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Update and draw
drawField(time);
drawParticles(time);
// Update particles
particles.forEach(p => {
updateParticle(p, time);
// Random mutation
if (Math.random() < 0.01) {
p.hue = (p.hue + 20 * (Math.random() - 0.5) + 360) % 360;
}
});
time += 0.05;
requestAnimationFrame(animate);
}
// Start animation
animate();
</script>
</body>
</html>