fractal-echoes-in-static-2lhs/index.html

136 lines
No EOL
3.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;
padding: 0;
overflow: hidden;
background: #0a0a0a;
font-family: 'Courier New', monospace;
}
canvas {
display: block;
}
#info {
position: absolute;
bottom: 10px;
left: 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="info">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();
// Strange attractor parameters
const params = {
a: 2.24,
b: 0.43,
c: -0.65,
d: -2.43,
e: 1.0,
scale: 200,
speed: 0.552 * 2,
points: 5000,
trails: 500,
hue: 180,
saturation: 20,
brightness: 80,
alpha: 0.4
};
const points = [];
const history = [];
function initPoints() {
for (let i = 0; i < params.points; i++) {
points.push({
x: Math.random() * 2 - 1,
y: Math.random() * 2 - 1,
trail: []
});
}
}
function updatePoints() {
for (let i = 0; i < points.length; i++) {
const p = points[i];
const x = p.x;
const y = p.y;
// Strange attractor equations
const x_new = Math.sin(params.a * y) - Math.cos(params.b * x);
const y_new = Math.sin(params.c * x) - Math.cos(params.d * y);
p.x = x_new * params.e + x * 0.1;
p.y = y_new * params.e + y * 0.1;
// Add to trail
p.trail.push({x: p.x, y: p.y});
if (p.trail.length > params.trails) {
p.trail.shift();
}
}
}
function draw() {
ctx.fillStyle = 'rgba(5, 5, 10, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const scale = Math.min(canvas.width, canvas.height) * 0.4;
ctx.lineWidth = 0.5;
ctx.strokeStyle = `hsla(${params.hue}, ${params.saturation}%, ${params.brightness}%, ${params.alpha})`;
for (let i = 0; i < points.length; i++) {
const p = points[i];
if (p.trail.length > 1) {
ctx.beginPath();
for (let j = 0; j < p.trail.length; j++) {
const pos = p.trail[j];
const x = centerX + pos.x * scale;
const y = centerY + pos.y * scale;
if (j === 0) {
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
}
ctx.stroke();
}
}
updatePoints();
}
function animate() {
draw();
requestAnimationFrame(animate);
}
initPoints();
animate();
</script>
</body>
</html>