whispering-fractal-galaxies.../index.html

170 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>Fractal Nebula</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
color: #aaa;
font-family: 'Courier New', monospace;
font-size: 10px;
}
canvas {
display: block;
}
#attribution {
position: absolute;
bottom: 10px;
right: 10px;
font-size: 10px;
color: #555;
}
</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');
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Parameters from prompt
const params = {
motion: 0.581,
density: 0.466,
complexity: 0.481,
connectedness: 0.575,
lifespan: 0.488,
pulse: { avg: 0.38, min: 0.3, max: 1.65 },
tone: { anger: 0.0, sadness: 0.0, curiosity: 0.1, dryness: 0.9, playfulness: 0.0, tension: 0.0 },
topology: {
nodes: 75,
branches: 67,
loops: 953,
maxDepth: 16,
thicknessRatio: 1.25,
fractalDim: 1.73,
energy: 445
}
};
// Fractal parameters
const maxDepth = Math.floor(params.topology.maxDepth * 2);
const branchCount = Math.floor(params.topology.branches * 0.8);
const thickness = Math.max(0.5, params.topology.thicknessRatio * 0.8);
// Color palette
const isMonochrome = params.tone.dryness > 0.8;
const baseHue = params.tone.curiosity > 0.5 ? 180 : 0;
const hueVariation = 20;
const saturation = isMonochrome ? 0 : 30 + Math.floor(params.topology.energy / 20);
const lightness = isMonochrome ? 20 + Math.floor(params.topology.energy / 15) : 40;
// Fractal node
class FractalNode {
constructor(x, y, depth = 0) {
this.x = x;
this.y = y;
this.depth = depth;
this.children = [];
this.age = 0;
this.maxAge = params.topology.maxDepth - depth;
this.size = thickness * (1 - depth / maxDepth) * (0.5 + params.density * 0.5);
this.targetSize = this.size * (0.8 + Math.random() * 0.4);
this.hue = baseHue + (Math.random() - 0.5) * hueVariation * 2;
}
grow() {
if (this.depth >= maxDepth) return;
const childCount = Math.floor(branchCount * (0.5 + 0.5 * params.connectedness));
for (let i = 0; i < childCount; i++) {
const angle = (i / childCount) * Math.PI * 2 + (Math.random() - 0.5) * 0.3;
const length = 20 + Math.random() * 30;
const branchThickness = this.size * 0.7;
const child = new FractalNode(
this.x + Math.cos(angle) * length,
this.y + Math.sin(angle) * length,
this.depth + 1
);
this.children.push(child);
}
}
update() {
this.age++;
this.size += (this.targetSize - this.size) * 0.1;
// Pulse effect
const pulseFactor = params.pulse.avg + (Math.random() - 0.5) * 0.2;
this.size *= 1 + (pulseFactor - 1) * 0.3;
this.children.forEach(child => child.update());
}
draw() {
if (this.depth > 0) {
ctx.beginPath();
ctx.moveTo(this.x, this.y);
ctx.lineTo(
this.x + (this.children[0]?.x - this.x) * 0.5,
this.y + (this.children[0]?.y - this.y) * 0.5
);
ctx.strokeStyle = isMonochrome ?
`hsl(0, 0%, ${lightness}%)` :
`hsl(${this.hue}, ${saturation}%, ${lightness}%)`;
ctx.lineWidth = this.size;
ctx.stroke();
// Draw children
this.children.forEach(child => child.draw());
}
}
}
// Create root nodes
const rootNodes = [];
for (let i = 0; i < params.topology.nodes; i++) {
rootNodes.push(new FractalNode(
canvas.width * 0.5 + (Math.random() - 0.5) * canvas.width * 0.8,
canvas.height * 0.5 + (Math.random() - 0.5) * canvas.height * 0.8
));
}
// Initial growth
rootNodes.forEach(node => node.grow());
// Animation loop
function animate() {
// Clear with slight fade
ctx.fillStyle = `rgba(10, 10, 10, ${0.05 + params.motion * 0.05})`;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Update and draw
rootNodes.forEach(node => {
node.update();
node.draw();
});
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>