birth: Neural Web of Drifting Echoes
This commit is contained in:
parent
96d51bbffd
commit
ea47f14cbc
1 changed files with 228 additions and 0 deletions
228
index.html
Normal file
228
index.html
Normal file
|
|
@ -0,0 +1,228 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Neural Drift</title>
|
||||
<style>
|
||||
body { margin: 0; overflow: hidden; background: #0a0a1a; }
|
||||
canvas { display: block; }
|
||||
#footer { position: fixed; bottom: 10px; right: 10px; color: #555; font-family: monospace; font-size: 10px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<div id="footer">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();
|
||||
|
||||
// Simulation parameters
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
pulse: { avg: 1.07, min: 0.9, max: 1.2 }
|
||||
};
|
||||
|
||||
// Node structure
|
||||
class Node {
|
||||
constructor(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.prevX = x;
|
||||
this.prevY = y;
|
||||
this.energy = Math.random();
|
||||
this.velocity = { x: 0, y: 0 };
|
||||
this.lifespan = params.lifespan * 100 + Math.random() * 50;
|
||||
this.color = Math.floor(Math.random() * 360);
|
||||
this.pulse = 1;
|
||||
}
|
||||
|
||||
update(targetNode = null) {
|
||||
// Apply pulse variation
|
||||
this.pulse = params.pulse.avg + (Math.random() * 2 - 1) * (params.pulse.max - params.pulse.min) * 0.5;
|
||||
|
||||
// Move toward target if connected
|
||||
if (targetNode) {
|
||||
const dx = targetNode.x - this.x;
|
||||
const dy = targetNode.y - this.y;
|
||||
const dist = Math.sqrt(dx * dx + dy * dy);
|
||||
const force = 0.01 * params.connectedness * dist;
|
||||
this.velocity.x += dx / dist * force * params.motion;
|
||||
this.velocity.y += dy / dist * force * params.motion;
|
||||
} else {
|
||||
// Random wandering
|
||||
this.velocity.x += (Math.random() - 0.5) * 0.02 * params.motion;
|
||||
this.velocity.y += (Math.random() - 0.5) * 0.02 * params.motion;
|
||||
}
|
||||
|
||||
// Apply physics
|
||||
this.velocity.x *= 0.95;
|
||||
this.velocity.y *= 0.95;
|
||||
this.prevX = this.x;
|
||||
this.prevY = this.y;
|
||||
this.x += this.velocity.x;
|
||||
this.y += this.velocity.y;
|
||||
|
||||
// Boundary check
|
||||
if (this.x < 0 || this.x > canvas.width || this.y < 0 || this.y > canvas.height) {
|
||||
this.x = Math.max(0, Math.min(canvas.width, this.x));
|
||||
this.y = Math.max(0, Math.min(canvas.height, this.y));
|
||||
this.velocity.x *= -0.5;
|
||||
this.velocity.y *= -0.5;
|
||||
}
|
||||
|
||||
// Lifespan decay
|
||||
this.lifespan--;
|
||||
this.energy = Math.max(0, this.lifespan / 100);
|
||||
}
|
||||
|
||||
draw() {
|
||||
const size = 2 + 3 * this.energy * this.pulse;
|
||||
const alpha = 0.3 + 0.7 * this.energy * this.pulse;
|
||||
|
||||
// Trail effect
|
||||
ctx.strokeStyle = `hsl(${this.color}, 70%, 60%, ${alpha})`;
|
||||
ctx.lineWidth = size * 0.5;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.prevX, this.prevY);
|
||||
ctx.lineTo(this.x, this.y);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
// Network structure
|
||||
class NetworkGraph {
|
||||
constructor() {
|
||||
this.nodes = [];
|
||||
this.connections = [];
|
||||
this.initNodes();
|
||||
this.initConnections();
|
||||
}
|
||||
|
||||
initNodes() {
|
||||
const count = Math.floor(params.density * params.density * 150) + 20;
|
||||
for (let i = 0; i < count; i++) {
|
||||
this.nodes.push(new Node(
|
||||
Math.random() * canvas.width,
|
||||
Math.random() * canvas.height
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
initConnections() {
|
||||
// Create a scale-free network using preferential attachment
|
||||
while (this.connections.length < Math.floor(params.connectedness * 50) + 5) {
|
||||
const a = Math.floor(Math.random() * this.nodes.length);
|
||||
const b = Math.floor(Math.random() * this.nodes.length);
|
||||
|
||||
if (a !== b && !this.isConnected(a, b)) {
|
||||
this.connections.push({ a, b });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isConnected(a, b) {
|
||||
return this.connections.some(conn =>
|
||||
(conn.a === a && conn.b === b) || (conn.a === b && conn.b === a)
|
||||
);
|
||||
}
|
||||
|
||||
update() {
|
||||
// Update all nodes
|
||||
for (let i = 0; i < this.nodes.length; i++) {
|
||||
const node = this.nodes[i];
|
||||
node.update();
|
||||
|
||||
// Find connected nodes and move toward them
|
||||
this.connections.forEach(conn => {
|
||||
if (conn.a === i) {
|
||||
node.update(this.nodes[conn.b]);
|
||||
} else if (conn.b === i) {
|
||||
node.update(this.nodes[conn.a]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Fade out dead nodes
|
||||
for (let i = this.nodes.length - 1; i >= 0; i--) {
|
||||
if (this.nodes[i].lifespan <= 0) {
|
||||
this.nodes.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Add new nodes to maintain density
|
||||
if (this.nodes.length < Math.floor(params.density * params.density * 150) + 20 &&
|
||||
Math.random() < 0.02 * (1 - params.density)) {
|
||||
this.nodes.push(new Node(
|
||||
Math.random() * canvas.width,
|
||||
Math.random() * canvas.height
|
||||
));
|
||||
}
|
||||
|
||||
// Maintain connection count
|
||||
if (Math.random() < 0.01 * params.connectedness) {
|
||||
const a = Math.floor(Math.random() * this.nodes.length);
|
||||
const b = Math.floor(Math.random() * this.nodes.length);
|
||||
|
||||
if (a !== b && !this.isConnected(a, b)) {
|
||||
this.connections.push({ a, b });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
draw() {
|
||||
// Draw connections first (background)
|
||||
ctx.lineCap = 'round';
|
||||
ctx.globalCompositeOperation = 'lighter';
|
||||
ctx.lineWidth = 0.5;
|
||||
|
||||
this.connections.forEach(conn => {
|
||||
const a = this.nodes[conn.a];
|
||||
const b = this.nodes[conn.b];
|
||||
const dist = Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);
|
||||
const alpha = 0.1 + 0.2 * params.connectedness * (1 - dist / Math.max(canvas.width, canvas.height));
|
||||
|
||||
ctx.strokeStyle = `hsl(${a.color}, 70%, 60%, ${alpha})`;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(a.x, a.y);
|
||||
ctx.lineTo(b.x, b.y);
|
||||
ctx.stroke();
|
||||
});
|
||||
|
||||
// Draw nodes (foreground)
|
||||
ctx.globalCompositeOperation = 'source-over';
|
||||
this.nodes.forEach(node => node.draw());
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize simulation
|
||||
let network = new NetworkGraph();
|
||||
|
||||
function animate() {
|
||||
// Clear with slight fade
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Update and draw
|
||||
if (Math.random() < 0.1) {
|
||||
network = new NetworkGraph(); // Occasionally reset to maintain complexity
|
||||
}
|
||||
network.update();
|
||||
network.draw();
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue