fractal-tremors-in-teal-dt9j/index.html

149 lines
No EOL
4.8 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 Strange Attractor</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
canvas {
display: block;
}
#attribution {
position: fixed;
bottom: 10px;
right: 10px;
color: #555;
font-family: monospace;
font-size: 10px;
text-shadow: 0 0 5px rgba(0,0,0,0.8);
}
</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();
// Strange attractor parameters
const params = {
a: 0.5 + Math.random() * 0.3,
b: 0.5 + Math.random() * 0.3,
c: 0.5 + Math.random() * 0.3,
d: 0.5 + Math.random() * 0.3,
scale: 10 * (0.5 + Math.random() * 0.5),
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
hue: 180 * (0.2 + Math.random() * 0.1) // teal range
};
// State
const points = [];
const maxPoints = 2000;
const trails = [];
const trailLength = 50;
// Initialize points
for (let i = 0; i < maxPoints * params.density; i++) {
points.push({
x: Math.random() * 2 - 1,
y: Math.random() * 2 - 1,
size: 0.2 + Math.random() * 0.3,
hue: params.hue,
trail: []
});
}
// Strange attractor function
function attractor(x, y, z, a, b, c, d) {
const x1 = Math.sin(a * y) - Math.cos(b * x);
const y1 = Math.sin(c * x) - Math.cos(d * z);
const z1 = Math.sin(x) - Math.cos(y);
return { x: x1, y: y1, z: z1 };
}
// Animation loop
function animate() {
// Clear with slight fade
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Update points
const time = performance.now() * 0.001 * params.motion;
points.forEach(p => {
// Apply attractor with small variations
const { x, y, z } = attractor(
p.x * params.scale + time,
p.y * params.scale + time * 1.3,
p.z || 0,
params.a + 0.1 * Math.sin(time * 0.3),
params.b + 0.1 * Math.cos(time * 0.2),
params.c + 0.1 * Math.sin(time * 0.4),
params.d + 0.1 * Math.cos(time * 0.3)
);
p.x = x;
p.y = y;
// Add to trail
p.trail.push({ x, y });
if (p.trail.length > trailLength) p.trail.shift();
});
// Draw trails
ctx.lineWidth = 0.5 * params.complexity;
points.forEach(p => {
if (p.trail.length < 2) return;
const gradient = ctx.createLinearGradient(
p.trail[0].x * canvas.width/4 + canvas.width/2,
p.trail[0].y * canvas.height/4 + canvas.height/2,
p.trail[p.trail.length-1].x * canvas.width/4 + canvas.width/2,
p.trail[p.trail.length-1].y * canvas.height/4 + canvas.height/2
);
gradient.addColorStop(0, `hsla(${p.hue}, 80%, 60%, 0)`);
gradient.addColorStop(0.5, `hsla(${p.hue}, 80%, 60%, 0.5)`);
gradient.addColorStop(1, `hsla(${p.hue}, 80%, 60%, 0)`);
ctx.strokeStyle = gradient;
ctx.beginPath();
p.trail.forEach((t, i) => {
const px = t.x * canvas.width/4 + canvas.width/2;
const py = t.y * canvas.height/4 + canvas.height/2;
if (i === 0) ctx.moveTo(px, py);
else ctx.lineTo(px, py);
});
ctx.stroke();
});
requestAnimationFrame(animate);
}
// Start animation
animate();
</script>
</body>
</html>