dancing-chaos-in-monochrome.../index.html

171 lines
No EOL
5.6 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;
font-family: 'Courier New', monospace;
color: #666;
}
#canvas {
display: block;
}
#attribution {
position: absolute;
bottom: 20px;
right: 20px;
font-size: 10px;
color: #333;
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');
// Set canvas to full window size
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Parameters derived from input
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: { avg: 1.08, min: 1.05, max: 1.10 },
tone: { dryness: 0.9, playfulness: 0.1 }
};
// Strange attractor parameters
const a = 20 * (1 + params.complexity * 2);
const b = 0.1 + params.motion * 0.5;
const c = 5 + params.connectedness * 15;
const d = 0.1 + params.lifespan * 0.9;
const scale = 0.2 + params.density * 1.8;
// Color based on tone.dryness and playfulness
const color = params.tone.playfulness > 0.5 ?
`hsl(${Math.random() * 60 + 180}, 70%, 80%)` :
`hsl(0, 0%, ${50 + Math.random() * 10}%)`;
// Strange attractor points
let points = [];
const pointCount = 500 + Math.floor(params.density * 5000);
// Initialize points in a spiral
function initPoints() {
points = [];
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const maxDist = Math.min(canvas.width, canvas.height) * 0.4;
for (let i = 0; i < pointCount; i++) {
const angle = (i / pointCount) * Math.PI * 2 * 10;
const dist = maxDist * Math.sqrt(Math.random());
points.push({
x: centerX + Math.cos(angle) * dist,
y: centerY + Math.sin(angle) * dist,
size: 1 + Math.random() * 3 * params.complexity,
life: 1,
pulse: params.pulse.avg + (Math.random() * (params.pulse.max - params.pulse.min) - (params.pulse.max - params.pulse.min)/2)
});
}
}
// Strange attractor iteration
function updatePoints() {
for (let p of points) {
const x = p.x - canvas.width/2;
const y = p.y - canvas.height/2;
// Strange attractor equations (Chua's circuit variant)
const xn = a * (y - x) + c * Math.sin(x);
const yn = b * x - y - d * Math.sin(z);
// Simple z equation for 3D-like effect
const zn = 0.1 * x;
p.x = xn * scale + canvas.width/2;
p.y = yn * scale + canvas.height/2;
z = zn;
p.life = Math.max(0, p.life - 0.002 * (1 - params.lifespan));
}
}
// Draw points
function drawPoints() {
ctx.globalAlpha = params.tone.dryness > 0.7 ? 0.3 : 0.6;
for (let p of points) {
if (p.life <= 0) continue;
const pulse = p.pulse * (1 + Math.sin(Date.now() * 0.001 * params.pulse.avg) * 0.1);
ctx.beginPath();
ctx.arc(p.x, p.y, p.size * pulse, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();
// Draw small trail lines
if (Math.random() < params.connectedness) {
ctx.strokeStyle = `rgba(255,255,255,${0.1 + p.life * 0.2})`;
ctx.lineWidth = p.size * 0.5 * params.complexity;
ctx.beginPath();
ctx.moveTo(p.x, p.y);
ctx.lineTo(
p.x + (Math.random() - 0.5) * 10 * params.motion,
p.y + (Math.random() - 0.5) * 10 * params.motion
);
ctx.stroke();
}
}
// Add some new points occasionally
if (Math.random() < 0.1 * params.motion) {
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
points.push({
x: centerX + (Math.random() - 0.5) * 100,
y: centerY + (Math.random() - 0.5) * 100,
size: 1 + Math.random() * 3 * params.complexity,
life: 1,
pulse: params.pulse.avg
});
}
}
// Main animation loop
let z = 0;
function animate() {
// Clear with slight fade for trails
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
updatePoints();
drawPoints();
requestAnimationFrame(animate);
}
// Initialize and start
initPoints();
animate();
</script>
</body>
</html>