birth: Fractal Nebula Dreamscapes
This commit is contained in:
parent
2378df6bc8
commit
ee3bf2794b
1 changed files with 191 additions and 0 deletions
191
index.html
Normal file
191
index.html
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Organic Fractal Nebula</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 20px;
|
||||
left: 20px;
|
||||
color: rgba(255, 255, 255, 0.3);
|
||||
font-size: 10px;
|
||||
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
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
pulse: { avg: 1.1, min: 1.0, max: 1.3 },
|
||||
tone: { dryness: 0.8, playfulness: 0.1 }
|
||||
};
|
||||
|
||||
// Fractal settings
|
||||
const maxDepth = 4;
|
||||
const lengthScale = 10;
|
||||
const angleStep = Math.PI / 4;
|
||||
const decayRate = 0.7;
|
||||
const branchCount = 3;
|
||||
const thickness = params.tone.dryness > 0.7 ? 1 : 2;
|
||||
|
||||
// State
|
||||
const branches = [];
|
||||
const particles = [];
|
||||
const colors = ['rgba(255,255,255,0.3)', 'rgba(200,200,200,0.2)'];
|
||||
|
||||
// Initialize
|
||||
function init() {
|
||||
branches.length = 0;
|
||||
particles.length = 0;
|
||||
|
||||
// Initial branches
|
||||
for (let i = 0; i < 5 * params.density; i++) {
|
||||
branches.push({
|
||||
x: canvas.width / 2,
|
||||
y: canvas.height / 2,
|
||||
length: lengthScale,
|
||||
angle: Math.random() * Math.PI * 2,
|
||||
depth: 0,
|
||||
parent: null,
|
||||
color: colors[Math.floor(Math.random() * colors.length)],
|
||||
thickness: thickness * (1 - params.complexity * 0.3)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Recursive fractal growth
|
||||
function growBranch(branch) {
|
||||
if (branch.depth >= maxDepth) return;
|
||||
|
||||
const angleVariation = angleStep * (1 - params.connectedness);
|
||||
const newBranches = [];
|
||||
|
||||
for (let i = 0; i < branchCount; i++) {
|
||||
const newAngle = branch.angle + (Math.random() - 0.5) * angleVariation;
|
||||
const newLength = branch.length * (0.7 + Math.random() * 0.3);
|
||||
const newThickness = branch.thickness * decayRate;
|
||||
|
||||
if (newThickness < 0.3) continue;
|
||||
|
||||
const newX = branch.x + Math.cos(newAngle) * branch.length;
|
||||
const newY = branch.y + Math.sin(newAngle) * branch.length;
|
||||
|
||||
const newBranch = {
|
||||
x: newX,
|
||||
y: newY,
|
||||
length: newLength,
|
||||
angle: newAngle,
|
||||
depth: branch.depth + 1,
|
||||
parent: branch,
|
||||
color: colors[Math.floor(Math.random() * colors.length)],
|
||||
thickness: newThickness
|
||||
};
|
||||
|
||||
branches.push(newBranch);
|
||||
newBranches.push(newBranch);
|
||||
|
||||
// Add particles along branch
|
||||
const particleCount = 2 * params.density * (1 - branch.depth/maxDepth);
|
||||
for (let p = 0; p < particleCount; p++) {
|
||||
particles.push({
|
||||
x: branch.x + (newX - branch.x) * (p / particleCount),
|
||||
y: branch.y + (newY - branch.y) * (p / particleCount),
|
||||
age: 0,
|
||||
maxAge: 30 + Math.random() * 30,
|
||||
size: newThickness * 2,
|
||||
color: colors[0]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Continue growing from new branches
|
||||
newBranches.forEach(growBranch);
|
||||
}
|
||||
|
||||
// Animation loop
|
||||
function animate() {
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Update and draw branches
|
||||
branches.forEach(branch => {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(branch.x, branch.y);
|
||||
ctx.lineTo(
|
||||
branch.x + Math.cos(branch.angle) * branch.length,
|
||||
branch.y + Math.sin(branch.angle) * branch.length
|
||||
);
|
||||
ctx.strokeStyle = branch.color;
|
||||
ctx.lineWidth = branch.thickness;
|
||||
ctx.stroke();
|
||||
});
|
||||
|
||||
// Update and draw particles
|
||||
particles.forEach((particle, i) => {
|
||||
particle.age++;
|
||||
if (particle.age > particle.maxAge) {
|
||||
particles.splice(i, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Slight movement based on motion parameter
|
||||
const pulse = params.pulse.avg * (1 + 0.1 * Math.sin(Date.now() * 0.001));
|
||||
particle.x += (Math.random() - 0.5) * 2 * params.motion;
|
||||
particle.y += (Math.random() - 0.5) * 2 * params.motion;
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
|
||||
ctx.fillStyle = particle.color;
|
||||
ctx.fill();
|
||||
});
|
||||
|
||||
// Occasionally grow new branches
|
||||
if (Math.random() < 0.05 * params.complexity) {
|
||||
const tipBranches = branches.filter(b => b.depth === maxDepth);
|
||||
if (tipBranches.length > 0) {
|
||||
growBranch(tipBranches[Math.floor(Math.random() * tipBranches.length)]);
|
||||
}
|
||||
}
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
init();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue