birth: Fractal Bloom in Monochrome
This commit is contained in:
parent
b1404cf85f
commit
2eeb2e6cfb
1 changed files with 195 additions and 0 deletions
195
index.html
Normal file
195
index.html
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Fractal Bloom</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
font-family: 'Courier New', monospace;
|
||||
color: #ccc;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
left: 20px;
|
||||
bottom: 20px;
|
||||
font-size: 10px;
|
||||
opacity: 0.5;
|
||||
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');
|
||||
|
||||
function resizeCanvas() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
|
||||
window.addEventListener('resize', resizeCanvas);
|
||||
resizeCanvas();
|
||||
|
||||
// Parameters derived from spec
|
||||
const params = {
|
||||
motion: 0.453,
|
||||
density: 0.441,
|
||||
complexity: 0.531,
|
||||
connectedness: 0.413,
|
||||
lifespan: 0.546,
|
||||
pulse: { avg: 0.97, min: 0.30, max: 2.00 },
|
||||
tone: { dryness: 0.90 },
|
||||
topology: {
|
||||
nodes: 9,
|
||||
branches: 9,
|
||||
loops: 51,
|
||||
maxDepth: 17,
|
||||
thicknessRatio: 1.25,
|
||||
fractalDim: 1.000,
|
||||
energy: 42.9
|
||||
}
|
||||
};
|
||||
|
||||
// Fractal parameters
|
||||
const maxDepth = Math.floor(10 + params.topology.maxDepth * 2);
|
||||
const branchCount = Math.floor(3 + params.topology.branches * 0.5);
|
||||
const growthRate = params.motion * 1.5;
|
||||
const angleVariation = params.complexity * Math.PI * 0.8;
|
||||
const segmentLength = 10 + params.density * 30;
|
||||
const thickness = 0.5 + params.topology.thicknessRatio * 0.5;
|
||||
|
||||
// Color palette (dryness = monochrome)
|
||||
const baseHue = 220;
|
||||
const saturation = 10 + params.tone.dryness * 10;
|
||||
const baseBrightness = 80;
|
||||
const pulseEffect = () => 0.7 + params.pulse.avg * 0.3;
|
||||
|
||||
// Fractal state
|
||||
const branches = [];
|
||||
let time = 0;
|
||||
let branchesCreated = 0;
|
||||
|
||||
// Initialize fractal
|
||||
function initFractal() {
|
||||
branches.length = 0;
|
||||
branchesCreated = 0;
|
||||
time = 0;
|
||||
|
||||
// Root branch
|
||||
branches.push({
|
||||
x: canvas.width / 2,
|
||||
y: canvas.height,
|
||||
angle: -Math.PI / 2,
|
||||
length: 1,
|
||||
depth: 0,
|
||||
thickness: thickness * 5,
|
||||
hue: baseHue,
|
||||
brightness: baseBrightness,
|
||||
children: []
|
||||
});
|
||||
}
|
||||
|
||||
// Grow fractal
|
||||
function growFractal() {
|
||||
if (branchesCreated >= maxDepth || Math.random() > growthRate) return;
|
||||
|
||||
const available = branches.filter(b => b.children.length < branchCount * 0.7);
|
||||
if (available.length === 0) return;
|
||||
|
||||
const parent = available[Math.floor(Math.random() * available.length)];
|
||||
const newAngle = parent.angle + (Math.random() - 0.5) * angleVariation;
|
||||
const newLength = parent.length * (0.6 + Math.random() * 0.4);
|
||||
|
||||
const newBranch = {
|
||||
x: parent.x + Math.cos(parent.angle) * parent.length * segmentLength,
|
||||
y: parent.y + Math.sin(parent.angle) * parent.length * segmentLength,
|
||||
angle: newAngle,
|
||||
length: newLength,
|
||||
depth: parent.depth + 1,
|
||||
parent: parent,
|
||||
thickness: parent.thickness * 0.7,
|
||||
hue: baseHue + (parent.depth % 3) * 20,
|
||||
brightness: baseBrightness * (0.7 + parent.depth * 0.05),
|
||||
children: [],
|
||||
creationTime: time,
|
||||
maxLife: 100 + params.topology.maxDepth * 10
|
||||
};
|
||||
|
||||
parent.children.push(newBranch);
|
||||
branches.push(newBranch);
|
||||
branchesCreated++;
|
||||
|
||||
// Add loops (close some branches back to ancestors)
|
||||
if (params.topology.loops > 0 && parent.depth > 2 && Math.random() < 0.3) {
|
||||
const loopTarget = branches[Math.floor(Math.random() * branches.length)];
|
||||
if (loopTarget.depth < parent.depth) {
|
||||
newBranch.angle = Math.atan2(
|
||||
loopTarget.y - newBranch.y,
|
||||
loopTarget.x - newBranch.x
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw fractal
|
||||
function drawFractal() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
ctx.lineCap = 'round';
|
||||
ctx.lineJoin = 'round';
|
||||
|
||||
branches.forEach(branch => {
|
||||
const lifeRatio = (time - branch.creationTime) / branch.maxLife;
|
||||
if (lifeRatio > 1) return;
|
||||
|
||||
const opacity = params.lifespan * (1 - lifeRatio * 0.7);
|
||||
const pulse = pulseEffect() * (1 - lifeRatio * 0.5);
|
||||
ctx.globalAlpha = opacity;
|
||||
|
||||
ctx.strokeStyle = `hsl(${branch.hue}, ${saturation}%, ${branch.brightness * pulse}%)`;
|
||||
ctx.lineWidth = branch.thickness;
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(branch.x, branch.y);
|
||||
|
||||
// Draw curved path to parent
|
||||
const endX = branch.x + Math.cos(branch.angle) * branch.length * segmentLength;
|
||||
const endY = branch.y + Math.sin(branch.angle) * branch.length * segmentLength;
|
||||
|
||||
// Quadratic curve for organic feel
|
||||
const cp1x = branch.x + Math.cos(branch.angle) * branch.length * segmentLength * 0.3;
|
||||
const cp1y = branch.y + Math.sin(branch.angle) * branch.length * segmentLength * 0.3;
|
||||
|
||||
ctx.quadraticCurveTo(cp1x, cp1y, endX, endY);
|
||||
ctx.stroke();
|
||||
});
|
||||
|
||||
ctx.globalAlpha = 1;
|
||||
}
|
||||
|
||||
// Animation loop
|
||||
function animate() {
|
||||
growFractal();
|
||||
drawFractal();
|
||||
time++;
|
||||
|
||||
if (time > 2000 || branchesCreated >= maxDepth * 2) {
|
||||
initFractal();
|
||||
}
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
initFractal();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue