birth: Fractal Breathing in Monochrome
This commit is contained in:
parent
be5d2b3034
commit
2b13b2331d
1 changed files with 194 additions and 0 deletions
194
index.html
Normal file
194
index.html
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Generative Fractal Web</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background-color: #0a0a1a;
|
||||
font-family: 'Courier New', monospace;
|
||||
color: #fff;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
.info {
|
||||
position: absolute;
|
||||
bottom: 20px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
text-align: right;
|
||||
padding: 10px;
|
||||
font-size: 0.8em;
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<div class="info">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 based on input
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
pulse: {avg: 1.05, min: 1.0, max: 1.1},
|
||||
tone: {anger: 0.0, sadness: 0.0, curiosity: 0.1, dryness: 0.9, playfulness: 0.0, tension: 0.0}
|
||||
};
|
||||
|
||||
// Fractal system state
|
||||
const fractals = [];
|
||||
const maxDepth = Math.floor(5 + params.complexity * 5);
|
||||
const branchCount = Math.floor(3 + params.connectedness * 7);
|
||||
const densityFactor = Math.max(0.5, Math.min(2.0, 0.5 + params.density * 1.5));
|
||||
const motionFactor = params.motion * 0.5;
|
||||
const colorBase = params.tone.dryness > 0.7 ? '#e0e0e0' : '#ffffff';
|
||||
const colorVariation = params.tone.dryness > 0.7 ? 0.1 : 0.3;
|
||||
|
||||
class FractalBranch {
|
||||
constructor(x, y, angle, depth, parentAlpha = 1.0) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.angle = angle;
|
||||
this.depth = depth;
|
||||
this.parentAlpha = parentAlpha;
|
||||
this.alpha = parentAlpha * (0.7 + Math.random() * 0.3);
|
||||
this.length = 50 * (0.5 + Math.random() * 0.5) * (1 - depth/maxDepth) * densityFactor;
|
||||
this.width = 2 * (0.5 + Math.random() * 0.5) * (1 - depth/maxDepth) * densityFactor;
|
||||
this.children = [];
|
||||
this.lifespan = 1.0;
|
||||
this.maxLifespan = 1.0 + Math.random() * 0.5;
|
||||
this.pulse = params.pulse.avg;
|
||||
|
||||
if (depth > 0) {
|
||||
this.spawnChildren();
|
||||
}
|
||||
}
|
||||
|
||||
spawnChildren() {
|
||||
const angleVariation = Math.PI * (0.2 + 0.3 * (1 - params.complexity));
|
||||
const lengthVariation = 0.7 + 0.3 * params.complexity;
|
||||
|
||||
for (let i = 0; i < branchCount; i++) {
|
||||
const childAngle = this.angle +
|
||||
(Math.random() - 0.5) * angleVariation * (1 - this.depth/maxDepth);
|
||||
const childX = this.x + Math.cos(childAngle) * this.length * lengthVariation;
|
||||
const childY = this.y + Math.sin(childAngle) * this.length * lengthVariation;
|
||||
|
||||
const child = new FractalBranch(
|
||||
childX,
|
||||
childY,
|
||||
childAngle,
|
||||
this.depth - 1,
|
||||
this.alpha
|
||||
);
|
||||
this.children.push(child);
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
this.length *= this.pulse;
|
||||
this.pulse = params.pulse.avg + (Math.random() - 0.5) * (params.pulse.max - params.pulse.min) * motionFactor;
|
||||
|
||||
if (this.depth < maxDepth) {
|
||||
this.children.forEach(child => child.update());
|
||||
}
|
||||
|
||||
this.lifespan -= 0.001 * params.lifespan;
|
||||
if (this.lifespan <= 0) this.lifespan = 0;
|
||||
}
|
||||
|
||||
draw() {
|
||||
const alpha = this.alpha * this.lifespan;
|
||||
const hue = 200 + Math.floor(Math.random() * 30); // Teal range
|
||||
const saturation = 10 + Math.floor(Math.random() * 20);
|
||||
const lightness = 70 + Math.floor(Math.random() * 10);
|
||||
const color = `hsl(${hue}, ${saturation}%, ${lightness}%)`;
|
||||
|
||||
ctx.strokeStyle = color;
|
||||
ctx.lineWidth = this.width * (1 - this.depth/maxDepth);
|
||||
ctx.globalAlpha = alpha;
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.x, this.y);
|
||||
ctx.lineTo(
|
||||
this.x + Math.cos(this.angle) * this.length,
|
||||
this.y + Math.sin(this.angle) * this.length
|
||||
);
|
||||
ctx.stroke();
|
||||
|
||||
this.children.forEach(child => child.draw());
|
||||
}
|
||||
}
|
||||
|
||||
function initFractals() {
|
||||
const count = Math.floor(3 + params.density * 7);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const angle = Math.random() * Math.PI * 2;
|
||||
const x = canvas.width/2 + Math.cos(angle) * canvas.width/3 * 0.8;
|
||||
const y = canvas.height/2 + Math.sin(angle) * canvas.height/3 * 0.8;
|
||||
|
||||
fractals.push(new FractalBranch(
|
||||
x,
|
||||
y,
|
||||
angle,
|
||||
maxDepth - Math.floor(Math.random() * (maxDepth/2)),
|
||||
1.0
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
function animate() {
|
||||
// Clear with fade effect
|
||||
ctx.fillStyle = 'rgba(10, 10, 26, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Update and draw fractals
|
||||
fractals.forEach(fractal => {
|
||||
fractal.update();
|
||||
if (fractal.lifespan > 0) {
|
||||
fractal.draw();
|
||||
}
|
||||
});
|
||||
|
||||
// Occasionally add new fractals
|
||||
if (Math.random() < 0.02 * params.lifespan) {
|
||||
initFractals();
|
||||
}
|
||||
|
||||
// Limit fractal count
|
||||
if (fractals.length > 50) {
|
||||
fractals.shift();
|
||||
}
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
initFractals();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue