fractal-breath-of-curiosity.../index.html

155 lines
No EOL
5.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Generative Fractal Organism</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
color: #ccc;
font-family: 'Courier New', monospace;
}
#attribution {
position: fixed;
bottom: 10px;
right: 10px;
font-size: 10px;
opacity: 0.5;
}
</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();
// Fractal parameters based on input
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulse: {avg: 1.07, min: 1.0, max: 1.1},
tone: {
anger: 0.0,
sadness: 0.0,
curiosity: 0.7,
dryness: 0.8,
playfulness: 0.2,
tension: 0.0
}
};
// Fractal state
const fractal = {
branches: [],
maxDepth: 5 + Math.floor(params.complexity * 5),
branchCount: 5 + Math.floor(params.connectedness * 20),
angle: Math.PI/4,
length: 150,
decay: 0.7 + params.density * 0.2,
colorHue: 170 + params.tone.curiosity * 50,
colorSaturation: 30 + params.tone.playfulness * 50,
colorLightness: 50 + params.tone.dryness * 20,
pulse: params.pulse.avg
};
// Initialize fractal
function initFractal() {
fractal.branches = [];
for (let i = 0; i < fractal.branchCount; i++) {
fractal.branches.push({
x: canvas.width/2,
y: canvas.height,
angle: -Math.PI/2,
depth: 0,
thickness: 2 + Math.random() * 3,
color: `hsl(${fractal.colorHue}, ${fractal.colorSaturation}%, ${fractal.colorLightness}%)`
});
}
}
// Draw a branch
function drawBranch(branch) {
ctx.save();
ctx.translate(branch.x, branch.y);
ctx.rotate(branch.angle);
ctx.strokeStyle = branch.color;
ctx.lineWidth = branch.thickness * (1 - branch.depth/fractal.maxDepth);
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(0, -fractal.length * (1 - branch.depth/fractal.maxDepth));
ctx.stroke();
ctx.restore();
}
// Update fractal branches
function updateFractal() {
const newBranches = [];
for (const branch of fractal.branches) {
if (branch.depth < fractal.maxDepth && Math.random() > 0.3) {
// Split into two new branches
const leftAngle = branch.angle - fractal.angle * (0.5 + Math.random() * 0.5);
const rightAngle = branch.angle + fractal.angle * (0.5 + Math.random() * 0.5);
newBranches.push({
x: branch.x + Math.cos(branch.angle) * fractal.length * (1 - branch.depth/fractal.maxDepth),
y: branch.y + Math.sin(branch.angle) * fractal.length * (1 - branch.depth/fractal.maxDepth),
angle: leftAngle,
depth: branch.depth + 1,
thickness: branch.thickness * 0.8,
color: `hsl(${fractal.colorHue + params.tone.playfulness*30}, ${fractal.colorSaturation}, ${fractal.colorLightness - params.tone.dryness*20}%)`
});
newBranches.push({
x: branch.x + Math.cos(branch.angle) * fractal.length * (1 - branch.depth/fractal.maxDepth),
y: branch.y + Math.sin(branch.angle) * fractal.length * (1 - branch.depth/fractal.maxDepth),
angle: rightAngle,
depth: branch.depth + 1,
thickness: branch.thickness * 0.8,
color: `hsl(${fractal.colorHue - params.tone.playfulness*20}, ${fractal.colorSaturation}, ${fractal.colorLightness - params.tone.dryness*15}%)`
});
}
}
fractal.branches = fractal.branches.concat(newBranches);
}
// Animation loop
function animate(timestamp) {
// Clear with semi-transparent for trails
ctx.fillStyle = 'rgba(10, 10, 10, 0.1)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Adjust pulse
fractal.pulse = params.pulse.min + (params.pulse.max - params.pulse.min) * (0.5 + 0.5 * Math.sin(timestamp/1000));
updateFractal();
for (const branch of fractal.branches) {
drawBranch(branch);
}
requestAnimationFrame(animate);
}
initFractal();
requestAnimationFrame(animate);
</script>
</body>
</html>