199 lines
No EOL
6.3 KiB
HTML
199 lines
No EOL
6.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Recursive Nebula</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #000;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: absolute;
|
|
bottom: 10px;
|
|
color: rgba(255, 255, 255, 0.3);
|
|
font-family: monospace;
|
|
font-size: 12px;
|
|
}
|
|
</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 from prompt
|
|
const params = {
|
|
motion: 0.5,
|
|
density: 0.5,
|
|
complexity: 0.5,
|
|
connectedness: 0.5,
|
|
lifespan: 0.5,
|
|
pulse: { avg: 1.09, min: 0.95, max: 1.25 },
|
|
tone: { dryness: 0.9, curiosity: 0.1 }
|
|
};
|
|
|
|
// State variables
|
|
const branches = [];
|
|
const particles = [];
|
|
let time = 0;
|
|
const maxBranches = 100;
|
|
const baseSize = Math.min(canvas.width, canvas.height) * 0.01;
|
|
const color = params.tone.dryness > 0.7 ? '#fff' : '#bbb';
|
|
|
|
// Recursive fractal generation
|
|
function generateFractal(x, y, angle, depth = 0, branchLength = baseSize) {
|
|
if (depth > 4 || branches.length >= maxBranches) return;
|
|
|
|
const length = branchLength * (0.5 + 0.5 * params.pulse.avg);
|
|
const endX = x + Math.cos(angle) * length;
|
|
const endY = y + Math.sin(angle) * length;
|
|
|
|
branches.push({
|
|
x, y, endX, endY,
|
|
depth,
|
|
angle,
|
|
length,
|
|
maxDepth: 4,
|
|
life: params.lifespan * 100 + 50
|
|
});
|
|
|
|
// Generate child branches
|
|
const childCount = Math.floor(3 + 5 * params.complexity);
|
|
const angleVariation = Math.PI * 0.3 * (0.5 + params.motion);
|
|
|
|
for (let i = 0; i < childCount; i++) {
|
|
const childAngle = angle + (Math.random() * angleVariation - angleVariation/2);
|
|
generateFractal(
|
|
endX, endY,
|
|
childAngle,
|
|
depth + 1,
|
|
length * (0.5 + 0.5 * Math.random())
|
|
);
|
|
}
|
|
}
|
|
|
|
// Initialize with some fractals
|
|
function init() {
|
|
for (let i = 0; i < 3; i++) {
|
|
generateFractal(
|
|
canvas.width/2,
|
|
canvas.height/2,
|
|
Math.random() * Math.PI * 2,
|
|
0
|
|
);
|
|
}
|
|
}
|
|
|
|
// Update fractal branches
|
|
function updateBranches() {
|
|
for (let i = branches.length - 1; i >= 0; i--) {
|
|
const branch = branches[i];
|
|
|
|
// Age and remove old branches
|
|
branch.life--;
|
|
if (branch.life <= 0) {
|
|
branches.splice(i, 1);
|
|
continue;
|
|
}
|
|
|
|
// Grow new branches occasionally
|
|
if (Math.random() < 0.02 * params.motion) {
|
|
generateFractal(
|
|
branch.endX, branch.endY,
|
|
branch.angle + (Math.random() - 0.5) * Math.PI/2,
|
|
branch.depth + 1,
|
|
branch.length * (0.6 + 0.4 * Math.random())
|
|
);
|
|
}
|
|
}
|
|
|
|
// Occasionally add new root branches
|
|
if (Math.random() < 0.01 * params.density && branches.length < maxBranches) {
|
|
generateFractal(
|
|
Math.random() * canvas.width,
|
|
Math.random() * canvas.height,
|
|
Math.random() * Math.PI * 2
|
|
);
|
|
}
|
|
}
|
|
|
|
// Draw everything
|
|
function draw() {
|
|
// Clear with slight fade
|
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
// Draw all branches
|
|
branches.forEach(branch => {
|
|
const alpha = branch.life / (params.lifespan * 100 + 50);
|
|
ctx.strokeStyle = color + Math.floor(alpha * 255).toString(16).padStart(2, '0');
|
|
ctx.lineWidth = 0.5 + branch.depth;
|
|
ctx.beginPath();
|
|
ctx.moveTo(branch.x, branch.y);
|
|
ctx.lineTo(branch.endX, branch.endY);
|
|
ctx.stroke();
|
|
});
|
|
|
|
// Draw some particles for motion
|
|
if (params.motion > 0.3 && Math.random() < 0.1) {
|
|
particles.push({
|
|
x: Math.random() * canvas.width,
|
|
y: Math.random() * canvas.height,
|
|
size: 0.5 + Math.random() * 2,
|
|
speed: 0.1 + Math.random() * 0.5,
|
|
angle: Math.random() * Math.PI * 2,
|
|
life: 30 + Math.random() * 70,
|
|
color: color
|
|
});
|
|
}
|
|
|
|
// Update and draw particles
|
|
particles.forEach((p, i) => {
|
|
p.x += Math.cos(p.angle) * p.speed;
|
|
p.y += Math.sin(p.angle) * p.speed;
|
|
p.life--;
|
|
|
|
ctx.fillStyle = p.color + Math.floor((p.life/100) * 255).toString(16).padStart(2, '0');
|
|
ctx.beginPath();
|
|
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
|
ctx.fill;
|
|
|
|
if (p.life <= 0) particles.splice(i, 1);
|
|
});
|
|
}
|
|
|
|
// Animation loop
|
|
function animate() {
|
|
updateBranches();
|
|
draw();
|
|
time += 0.01;
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
// Start everything
|
|
init();
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |