birth: Semi-living network pulses
This commit is contained in:
parent
a8cb18aa86
commit
65cf21e069
1 changed files with 256 additions and 0 deletions
256
index.html
Normal file
256
index.html
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Neurameba Motd.Social</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
color: #444;
|
||||
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');
|
||||
|
||||
// Set canvas to full window size
|
||||
function resizeCanvas() {
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
}
|
||||
window.addEventListener('resize', resizeCanvas);
|
||||
resizeCanvas();
|
||||
|
||||
// Configuration based on parameters
|
||||
const config = {
|
||||
motion: 0.531,
|
||||
density: 0.516,
|
||||
complexity: 0.469,
|
||||
connectedness: 0.420,
|
||||
lifespan: 0.502,
|
||||
pulse: {
|
||||
avg: 0.65,
|
||||
min: 0.30,
|
||||
max: 1.80
|
||||
},
|
||||
tone: {
|
||||
anger: 0.00,
|
||||
sadness: 0.00,
|
||||
curiosity: 0.60,
|
||||
dryness: 0.90,
|
||||
playfulness: 0.10,
|
||||
tension: 0.00
|
||||
},
|
||||
topology: {
|
||||
survivingNodes: 86,
|
||||
branchCount: 62,
|
||||
loops: 182,
|
||||
maxDepth: 20,
|
||||
thicknessRatio: 1.25,
|
||||
fractalDimension: 1.616,
|
||||
finalEnergy: 432.5
|
||||
}
|
||||
};
|
||||
|
||||
// Network Node class
|
||||
class Node {
|
||||
constructor(x, y, id) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.id = id;
|
||||
this.radius = Math.random() * 4 + 1.5;
|
||||
this.baseColor = `hsl(${Math.random() * 30 + 160}, 80%, 70%)`;
|
||||
this.connections = [];
|
||||
this.pulsePhase = Math.random() * Math.PI * 2;
|
||||
this.age = 0;
|
||||
this.maxAge = config.lifespan < 0.5 ?
|
||||
200 + Math.random() * 300 :
|
||||
Infinity;
|
||||
}
|
||||
|
||||
connectTo(node) {
|
||||
this.connections.push(node);
|
||||
node.connections.push(this);
|
||||
}
|
||||
|
||||
update(energy) {
|
||||
this.age++;
|
||||
if (this.age > this.maxAge) return false;
|
||||
|
||||
this.pulsePhase += config.pulse.avg * 0.01;
|
||||
return true;
|
||||
}
|
||||
|
||||
draw() {
|
||||
const pulse = Math.sin(this.pulsePhase) * 0.5 + 0.5;
|
||||
const size = this.radius * (1 + pulse * 0.3);
|
||||
const alpha = Math.min(1, this.age / 50);
|
||||
const color = `hsla(${this.baseColor.replace('hsl(', '').split(',')[0]}, ${80 * alpha}%, ${70 * alpha}%, 1)`;
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(this.x, this.y, size, 0, Math.PI * 2);
|
||||
ctx.fillStyle = color;
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = `rgba(255,255,255,${0.3 * alpha})`;
|
||||
ctx.lineWidth = 0.5 * pulse;
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
// Network Graph class
|
||||
class NetworkGraph {
|
||||
constructor() {
|
||||
this.nodes = [];
|
||||
this.edges = [];
|
||||
this.energy = config.topology.finalEnergy;
|
||||
this.initNodes();
|
||||
this.initConnections();
|
||||
}
|
||||
|
||||
initNodes() {
|
||||
const spacing = Math.min(canvas.width, canvas.height) / (10 + config.density * 20);
|
||||
const rows = Math.ceil(canvas.height / spacing);
|
||||
const cols = Math.ceil(canvas.width / spacing);
|
||||
|
||||
for (let i = 0; i < config.topology.survivingNodes; i++) {
|
||||
const x = Math.random() * canvas.width;
|
||||
const y = Math.random() * canvas.height;
|
||||
this.nodes.push(new Node(x, y, i));
|
||||
}
|
||||
}
|
||||
|
||||
initConnections() {
|
||||
// Create a small-world network with some random connections
|
||||
for (let i = 0; i < this.nodes.length; i++) {
|
||||
if (Math.random() > config.connectedness) continue;
|
||||
|
||||
// Connect to nearby nodes first
|
||||
const nearby = this.nodes
|
||||
.map(n => ({
|
||||
node: n,
|
||||
dist: Math.hypot(n.x - this.nodes[i].x, n.y - this.nodes[i].y)
|
||||
}))
|
||||
.filter(n => n.dist > 0 && n.dist < canvas.width * 0.2)
|
||||
.sort((a, b) => a.dist - b.dist)
|
||||
.slice(0, 3 + Math.floor(config.complexity * 5));
|
||||
|
||||
nearby.forEach(n => this.nodes[i].connectTo(n.node));
|
||||
|
||||
// Add some random long-range connections
|
||||
if (this.nodes[i].connections.length < 3 && Math.random() < 0.3) {
|
||||
const randomNode = this.nodes[Math.floor(Math.random() * this.nodes.length)];
|
||||
if (randomNode !== this.nodes[i]) {
|
||||
this.nodes[i].connectTo(randomNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure we have some loops
|
||||
for (let i = 0; i < config.topology.loops; i++) {
|
||||
const node1 = this.nodes[Math.floor(Math.random() * this.nodes.length)];
|
||||
const node2 = this.nodes[Math.floor(Math.random() * this.nodes.length)];
|
||||
const node3 = this.nodes[Math.floor(Math.random() * this.nodes.length)];
|
||||
|
||||
if (node1 !== node2 && node2 !== node3 && node1 !== node3) {
|
||||
// Create a triangle
|
||||
node1.connectTo(node2);
|
||||
node2.connectTo(node3);
|
||||
node1.connectTo(node3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
this.energy = config.topology.finalEnergy * (0.8 + 0.4 * Math.random());
|
||||
|
||||
// Update all nodes
|
||||
for (let i = this.nodes.length - 1; i >= 0; i--) {
|
||||
if (!this.nodes[i].update(this.energy)) {
|
||||
this.nodes.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Die off some nodes based on energy
|
||||
if (this.energy < 200 && Math.random() < 0.01) {
|
||||
if (this.nodes.length > 20) {
|
||||
this.nodes.splice(Math.floor(Math.random() * this.nodes.length), 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Add new nodes occasionally
|
||||
if (Math.random() < 0.02 && this.nodes.length < 150) {
|
||||
this.nodes.push(new Node(
|
||||
Math.random() * canvas.width,
|
||||
Math.random() * canvas.height,
|
||||
this.nodes.length
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
draw() {
|
||||
// Draw connections with thickness based on energy and pulse
|
||||
this.nodes.forEach(node => {
|
||||
node.connections.forEach(connection => {
|
||||
if (node.id < connection.id) { // Avoid duplicate draws
|
||||
const pulse = (Math.sin(node.pulsePhase) + Math.sin(connection.pulsePhase)) * 0.25 + 0.5;
|
||||
const energyFactor = this.energy / 500;
|
||||
const thickness = Math.max(0.5, config.topology.thicknessRatio * 2 * pulse * energyFactor);
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(node.x, node.y);
|
||||
ctx.lineTo(connection.x, connection.y);
|
||||
ctx.strokeStyle = `hsla(${node.baseColor.replace('hsl(', '').split(',')[0]}, 60%, 70%, ${0.2 * energyFactor})`;
|
||||
ctx.lineWidth = thickness;
|
||||
ctx.stroke();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Draw nodes
|
||||
this.nodes.forEach(node => node.draw());
|
||||
}
|
||||
}
|
||||
|
||||
// Main animation
|
||||
let graph = new NetworkGraph();
|
||||
let frameCount = 0;
|
||||
|
||||
function animate() {
|
||||
// Clear with subtle trails
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
graph.update();
|
||||
graph.draw();
|
||||
|
||||
frameCount++;
|
||||
if (frameCount % 300 === 0) {
|
||||
// Occasionally reset with new energy levels
|
||||
graph = new NetworkGraph();
|
||||
}
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue