birth: Fractal Pulse in Fractured Motion
This commit is contained in:
parent
dd6bd4f31d
commit
39fe9510b3
1 changed files with 287 additions and 0 deletions
287
index.html
Normal file
287
index.html
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Neurameba Organism</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
font-family: 'Courier New', monospace;
|
||||
color: #aaa;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
}
|
||||
#canvas {
|
||||
flex: 1;
|
||||
}
|
||||
#attribution {
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
font-size: 10px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<div id="attribution">neurameba · motd.social</div>
|
||||
<script>
|
||||
(function() {
|
||||
const canvas = document.getElementById('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
// Set canvas to full window size
|
||||
function resizeCanvas() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
window.addEventListener('resize', resizeCanvas);
|
||||
resizeCanvas();
|
||||
|
||||
// Parameters derived from the abstract description
|
||||
const params = {
|
||||
motion: 0.663,
|
||||
density: 0.431,
|
||||
complexity: 0.747,
|
||||
connectedness: 0.579,
|
||||
lifespan: 0.339,
|
||||
survivingNodes: 6,
|
||||
branchCount: 4,
|
||||
loops: 10,
|
||||
maxDepth: 6,
|
||||
thicknessRatio: 1.00,
|
||||
fractalDimension: 0.500,
|
||||
energy: 47.0,
|
||||
pulse: { avg: 0.35, min: 0.30, max: 1.20 },
|
||||
tone: { anger: 0.00, sadness: 0.00, curiosity: 0.70, dryness: 0.90, playfulness: 0.00, tension: 0.00 }
|
||||
};
|
||||
|
||||
// Derived configuration
|
||||
const config = {
|
||||
angle: Math.PI / 4 * params.complexity,
|
||||
angleVariation: params.connectedness * 0.5,
|
||||
segmentLength: 10 + params.density * 30,
|
||||
recursionDepth: params.maxDepth,
|
||||
loopCount: params.loops,
|
||||
color: `hsl(${200 + params.tone.curiosity * 80}, 30%, ${60 + params.tone.dryness * 20}%)`,
|
||||
strokeWidth: 1 + params.thicknessRatio * 3,
|
||||
maxEnergy: params.energy
|
||||
};
|
||||
|
||||
// L-system rules
|
||||
const lSystem = {
|
||||
axiom: 'X',
|
||||
rules: {
|
||||
'F': 'FF+[+F-F-F]-[-F+F+F]',
|
||||
'X': 'F-[[X]+X]+F[+FX]-X'
|
||||
},
|
||||
iterations: 3 + Math.floor(params.complexity * 3),
|
||||
angle: config.angle,
|
||||
length: config.segmentLength,
|
||||
lengthDecay: 0.75,
|
||||
lengthVariation: 0.1 * params.connectedness,
|
||||
angleVariation: config.angleVariation,
|
||||
maxDepth: config.recursionDepth,
|
||||
currentDepth: 0
|
||||
};
|
||||
|
||||
// State variables
|
||||
let time = 0;
|
||||
const organisms = [];
|
||||
const decayRate = 0.99;
|
||||
|
||||
// Organism class
|
||||
class Organism {
|
||||
constructor(x, y, angle, depth, color) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.angle = angle;
|
||||
this.depth = depth;
|
||||
this.color = color;
|
||||
this.length = lSystem.length * (0.5 + Math.random() * 0.5 * params.motion);
|
||||
this.maxLength = this.length;
|
||||
this.decay = 1.0;
|
||||
this.age = 0;
|
||||
this.trail = [];
|
||||
this.trailLength = 5 + Math.floor(params.lifespan * 20);
|
||||
this.pulse = params.pulse.min + Math.random() * (params.pulse.max - params.pulse.min);
|
||||
this.pulseTime = 0;
|
||||
}
|
||||
|
||||
update() {
|
||||
this.age++;
|
||||
this.pulseTime += 0.01;
|
||||
|
||||
// Apply pulse
|
||||
this.length = this.maxLength * (params.pulse.avg + Math.sin(this.pulseTime * this.pulse) * params.pulse.avg * 0.2);
|
||||
|
||||
// Decay
|
||||
this.decay *= decayRate;
|
||||
|
||||
// Add to trail
|
||||
this.trail.push({ x: this.x, y: this.y, alpha: this.decay });
|
||||
if (this.trail.length > this.trailLength) {
|
||||
this.trail.shift();
|
||||
}
|
||||
|
||||
// Movement
|
||||
this.x += Math.cos(this.angle) * this.length * params.motion;
|
||||
this.y += Math.sin(this.angle) * this.length * params.motion;
|
||||
|
||||
// Bounce off edges
|
||||
if (this.x < 0 || this.x > canvas.width) this.angle = Math.PI - this.angle;
|
||||
if (this.y < 0 || this.y > canvas.height) this.angle = -this.angle;
|
||||
}
|
||||
|
||||
draw() {
|
||||
ctx.strokeStyle = this.color;
|
||||
ctx.lineWidth = config.strokeWidth * this.decay;
|
||||
|
||||
// Draw trail
|
||||
this.trail.forEach((point, i) => {
|
||||
const alpha = point.alpha * (i / this.trail.length);
|
||||
ctx.globalAlpha = alpha * 0.5;
|
||||
ctx.beginPath();
|
||||
ctx.arc(point.x, point.y, config.strokeWidth * 0.5 * this.decay, 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
});
|
||||
ctx.globalAlpha = 1;
|
||||
|
||||
// Draw current segment
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.x, this.y);
|
||||
const nextX = this.x + Math.cos(this.angle) * this.length;
|
||||
const nextY = this.y + Math.sin(this.angle) * this.length;
|
||||
ctx.lineTo(nextX, nextY);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
// L-system expansion
|
||||
function expandLSystem(axiom, rules, iterations) {
|
||||
let current = axiom;
|
||||
for (let i = 0; i < iterations; i++) {
|
||||
let next = '';
|
||||
for (let j = 0; j < current.length; j++) {
|
||||
const char = current[j];
|
||||
next += rules[char] || char;
|
||||
}
|
||||
current = next;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
// Parse L-system string into drawing commands
|
||||
function parseLSystem(lSystem) {
|
||||
const commands = expandLSystem(lSystem.axiom, lSystem.rules, lSystem.iterations);
|
||||
const stack = [];
|
||||
const organisms = [];
|
||||
let currentX = canvas.width / 2;
|
||||
let currentY = canvas.height;
|
||||
let currentAngle = -Math.PI / 2;
|
||||
let currentDepth = 0;
|
||||
|
||||
for (let i = 0; i < commands.length; i++) {
|
||||
const cmd = commands[i];
|
||||
const colorVariation = 0.7 + Math.sin(time * 0.01 + i * 0.1) * 0.3;
|
||||
|
||||
switch (cmd) {
|
||||
case 'F':
|
||||
const newOrg = new Organism(
|
||||
currentX,
|
||||
currentY,
|
||||
currentAngle,
|
||||
currentDepth,
|
||||
config.color
|
||||
);
|
||||
organisms.push(newOrg);
|
||||
currentX += Math.cos(currentAngle) * newOrg.length;
|
||||
currentY += Math.sin(currentAngle) * newOrg.length;
|
||||
break;
|
||||
case '+':
|
||||
currentAngle += lSystem.angle + (Math.random() * 2 - 1) * lSystem.angleVariation;
|
||||
break;
|
||||
case '-':
|
||||
currentAngle -= lSystem.angle + (Math.random() * 2 - 1) * lSystem.angleVariation;
|
||||
break;
|
||||
case '[':
|
||||
stack.push({ x: currentX, y: currentY, angle: currentAngle, depth: currentDepth });
|
||||
currentDepth++;
|
||||
break;
|
||||
case ']':
|
||||
const state = stack.pop();
|
||||
if (state) {
|
||||
currentX = state.x;
|
||||
currentY = state.y;
|
||||
currentAngle = state.angle;
|
||||
currentDepth = state.depth;
|
||||
}
|
||||
break;
|
||||
case 'X':
|
||||
// Branch point - new organism at same position
|
||||
const branchOrg = new Organism(
|
||||
currentX,
|
||||
currentY,
|
||||
currentAngle + (Math.random() - 0.5) * 0.5,
|
||||
currentDepth,
|
||||
config.color
|
||||
);
|
||||
organisms.push(branchOrg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return organisms;
|
||||
}
|
||||
|
||||
// Initialize
|
||||
function init() {
|
||||
organisms.length = 0;
|
||||
organisms.push(...parseLSystem(lSystem));
|
||||
}
|
||||
|
||||
// Main animation loop
|
||||
function animate() {
|
||||
time += 0.01;
|
||||
|
||||
// Fade background slightly
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Update and draw all organisms
|
||||
for (let i = organisms.length - 1; i >= 0; i--) {
|
||||
organisms[i].update();
|
||||
organisms[i].draw();
|
||||
|
||||
// Remove dead organisms
|
||||
if (organisms[i].decay < 0.01) {
|
||||
organisms.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Occasionally add new random organisms
|
||||
if (Math.random() < 0.05 && organisms.length < 100) {
|
||||
const organism = new Organism(
|
||||
Math.random() * canvas.width,
|
||||
Math.random() * canvas.height,
|
||||
Math.random() * Math.PI * 2,
|
||||
0,
|
||||
config.color
|
||||
);
|
||||
organisms.push(organism);
|
||||
}
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
// Start animation
|
||||
init();
|
||||
animate();
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue