birth: Pulsing Network Dreamscape
This commit is contained in:
parent
5347025a97
commit
9deab771ae
1 changed files with 199 additions and 0 deletions
199
index.html
Normal file
199
index.html
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Neurameba Network</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background-color: #0a0a0a;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
#canvas {
|
||||
display: block;
|
||||
}
|
||||
#attribution {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
color: #444;
|
||||
font-size: 10px;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
</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();
|
||||
|
||||
// Parameters from brief
|
||||
const params = {
|
||||
motion: 0.5,
|
||||
density: 0.5,
|
||||
complexity: 0.5,
|
||||
connectedness: 0.5,
|
||||
lifespan: 0.5,
|
||||
pulse: { avg: 1.08, min: 1.05, max: 1.1 }
|
||||
};
|
||||
|
||||
// Network graph simulation
|
||||
class Node {
|
||||
constructor(x, y, id) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.id = id;
|
||||
this.vx = (Math.random() - 0.5) * params.motion * 2;
|
||||
this.vy = (Math.random() - 0.5) * params.motion * 2;
|
||||
this.size = 1 + Math.random() * params.density * 3;
|
||||
this.connections = [];
|
||||
this.createdAt = Date.now();
|
||||
this.lifespan = 5000 + Math.random() * 5000 * params.lifespan;
|
||||
this.color = '#' + Math.floor(Math.random() * 0x33 + 0xcc).toString(16).repeat(3);
|
||||
}
|
||||
|
||||
update(nodes) {
|
||||
// Simple attraction/repulsion
|
||||
nodes.forEach(node => {
|
||||
if (node !== this) {
|
||||
const dx = node.x - this.x;
|
||||
const dy = node.y - this.y;
|
||||
const dist = Math.sqrt(dx*dx + dy*dy);
|
||||
|
||||
if (dist < 100) {
|
||||
this.vx += dx * 0.01 * params.connectedness;
|
||||
this.vy += dy * 0.01 * params.connectedness;
|
||||
}
|
||||
|
||||
if (dist < 150) {
|
||||
if (Math.random() < params.complexity * 0.1 && this.connections.length < 10) {
|
||||
this.connections.push({
|
||||
target: node.id,
|
||||
strength: params.connectedness
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Apply velocity with some friction
|
||||
this.x += this.vx;
|
||||
this.y += this.vy;
|
||||
this.vx *= 0.97;
|
||||
this.vy *= 0.97;
|
||||
|
||||
// Boundary check
|
||||
if (this.x < 0 || this.x > canvas.width) this.vx *= -1;
|
||||
if (this.y < 0 || this.y > canvas.height) this.vy *= -1;
|
||||
|
||||
// Connection decay
|
||||
this.connections = this.connections.filter(conn => {
|
||||
return nodes.some(n => n.id === conn.target) &&
|
||||
Math.random() > (1 - params.connectedness * 0.01);
|
||||
});
|
||||
}
|
||||
|
||||
draw() {
|
||||
ctx.beginPath();
|
||||
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
|
||||
ctx.fillStyle = this.color;
|
||||
ctx.fill();
|
||||
|
||||
// Draw connections
|
||||
this.connections.forEach(conn => {
|
||||
const targetNode = nodes.find(n => n.id === conn.target);
|
||||
if (targetNode) {
|
||||
const alpha = Math.min(0.5, conn.strength * 0.5);
|
||||
ctx.strokeStyle = `rgba(255, 255, 255, ${alpha})`;
|
||||
ctx.lineWidth = 0.5 + conn.strength * 0.5;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.x, this.y);
|
||||
ctx.lineTo(targetNode.x, targetNode.y);
|
||||
ctx.stroke();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const nodes = [];
|
||||
let lastTime = 0;
|
||||
let nodeIdCounter = 0;
|
||||
|
||||
function init() {
|
||||
nodes.length = 0;
|
||||
nodeIdCounter = 0;
|
||||
|
||||
// Initial nodes based on density
|
||||
const initialNodes = Math.floor(50 + params.density * 150);
|
||||
for (let i = 0; i < initialNodes; i++) {
|
||||
nodes.push(new Node(
|
||||
Math.random() * canvas.width,
|
||||
Math.random() * canvas.height,
|
||||
nodeIdCounter++
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
function animate(time) {
|
||||
// Pulse adjustment
|
||||
const pulse = params.pulse.avg + Math.sin(time * 0.001) * 0.02;
|
||||
const scale = 1 + (pulse - 1) * 0.5;
|
||||
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.save();
|
||||
ctx.scale(scale, scale);
|
||||
ctx.translate((1 - scale) * canvas.width/2, (1 - scale) * canvas.height/2);
|
||||
|
||||
// Update and draw nodes
|
||||
nodes.forEach(node => {
|
||||
node.update(nodes);
|
||||
node.draw();
|
||||
});
|
||||
|
||||
// Randomly add new nodes
|
||||
if (Math.random() < 0.02 * params.density) {
|
||||
nodes.push(new Node(
|
||||
Math.random() * canvas.width,
|
||||
Math.random() * canvas.height,
|
||||
nodeIdCounter++
|
||||
));
|
||||
}
|
||||
|
||||
// Prune old nodes
|
||||
const now = Date.now();
|
||||
for (let i = nodes.length - 1; i >= 0; i--) {
|
||||
if (now - nodes[i].createdAt > nodes[i].lifespan) {
|
||||
nodes.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
|
||||
lastTime = time;
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
init();
|
||||
requestAnimationFrame(animate);
|
||||
|
||||
// Cleanup on unmount
|
||||
window.addEventListener('beforeunload', () => {
|
||||
cancelAnimationFrame(animate);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue