fractal-drift-through-still.../index.html

166 lines
No EOL
5.8 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 Drift</title>
<style>
body {
margin: 0;
overflow: hidden;
background: #0a0a0a;
color: #fff;
font-family: 'Courier New', monospace;
}
canvas {
display: block;
}
#attribution {
position: absolute;
bottom: 10px;
right: 10px;
font-size: 10px;
color: #555;
text-shadow: 0 0 5px rgba(0,0,0,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();
// Parametric configuration
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, sadness: 0, curiosity: 0, dryness: 0.9, playfulness: 0, tension: 0 }
};
// Color palette (dryness-heavy monochrome)
const palette = {
bg: '#0a0a0a',
fg: '#e0e0e0',
accent: '#a0a0a0',
pulseColor: '#ffffff'
};
// Fractal system parameters
const fractal = {
maxDepth: Math.floor(3 + params.complexity * 5),
branchAngle: 0.5 + params.connectedness * 0.5,
branchLength: 10 + params.density * 30,
lengthVariation: 0.3 * params.motion,
rotationSpeed: 0.01 + params.motion * 0.05,
pulseSpeed: params.pulse.avg,
pulseRange: params.pulse.max - params.pulse.min
};
// Node system
class FractalNode {
constructor(x, y, depth, angle, parent) {
this.x = x;
this.y = y;
this.depth = depth;
this.angle = angle;
this.parent = parent;
this.children = [];
this.lifespan = 1;
this.maxLifespan = 1 + params.lifespan * 2;
this.pulseProgress = Math.random();
this.targetLength = fractal.branchLength * (0.5 + 0.5 * Math.random());
if (depth < fractal.maxDepth) {
const childCount = 1 + Math.floor(params.connectedness * 3);
for (let i = 0; i < childCount; i++) {
const childAngle = this.angle + (Math.random() - 0.5) * fractal.branchAngle * 2;
const childX = this.x + Math.cos(childAngle) * this.targetLength;
const childY = this.y + Math.sin(childAngle) * this.targetLength;
const child = new FractalNode(childX, childY, depth + 1, childAngle, this);
this.children.push(child);
}
}
}
update(pulseFactor) {
this.lifespan += 0.005;
if (this.lifespan > this.maxLifespan) {
this.lifespan = this.maxLifespan;
}
this.pulseProgress += 0.01;
const pulseScale = 1 + Math.sin(this.pulseProgress * fractal.pulseSpeed) * 0.1 * fractal.pulseRange;
if (this.parent) {
this.x = this.parent.x + Math.cos(this.angle) * this.targetLength * pulseScale;
this.y = this.parent.y + Math.sin(this.angle) * this.targetLength * pulseScale;
}
this.children.forEach(child => child.update(pulseFactor));
}
draw(ctx, pulseFactor) {
if (this.depth === 0) return;
const progress = this.lifespan / this.maxLifespan;
const alpha = params.lifespan < 0.3 ? progress : 1 - Math.pow(1 - progress, 4);
const width = params.density * 2 + 1;
const color = `rgba(${224 + Math.floor(pulseFactor * 32)}, ${224 + Math.floor(pulseFactor * 32)}, ${224 + Math.floor(pulseFactor * 32)}, ${alpha * 0.8})`;
ctx.beginPath();
ctx.moveTo(this.parent.x, this.parent.y);
ctx.lineTo(this.x, this.y);
ctx.strokeStyle = color;
ctx.lineWidth = width * (1 - this.depth / fractal.maxDepth);
ctx.stroke();
this.children.forEach(child => child.draw(ctx, pulseFactor));
}
}
// Root nodes
let rootNodes = [];
const nodeCount = 1 + Math.floor(params.density * 3);
function init() {
rootNodes = [];
for (let i = 0; i < nodeCount; i++) {
const angle = (i / nodeCount) * Math.PI * 2;
const x = canvas.width / 2 + Math.cos(angle) * canvas.width * 0.3;
const y = canvas.height / 2 + Math.sin(angle) * canvas.height * 0.3;
rootNodes.push(new FractalNode(x, y, 0, angle, null));
}
}
function animate(timestamp) {
ctx.fillStyle = palette.bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
const pulseFactor = 1 + Math.sin(timestamp * 0.001) * 0.05;
rootNodes.forEach(root => {
root.update(pulseFactor);
root.draw(ctx, pulseFactor);
});
requestAnimationFrame(animate);
}
init();
animate(0);
</script>
</body>
</html>