165 lines
No EOL
5.6 KiB
HTML
165 lines
No EOL
5.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Organic Network</title>
|
|
<style>
|
|
body { margin: 0; overflow: hidden; background: #0a0a0a; }
|
|
canvas { display: block; }
|
|
#info { position: absolute; bottom: 10px; left: 10px; color: #ccc; font-family: monospace; font-size: 10px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="c"></canvas>
|
|
<div id="info">neurameba · motd.social</div>
|
|
<script>
|
|
const canvas = document.getElementById('c');
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
function resize() {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
}
|
|
window.addEventListener('resize', resize);
|
|
resize();
|
|
|
|
// Parameters
|
|
const params = {
|
|
motion: 0.5,
|
|
density: 0.5,
|
|
complexity: 0.5,
|
|
connectedness: 0.5,
|
|
lifespan: 0.5,
|
|
pulse: { avg: 1.11, min: 0.95, max: 1.30 },
|
|
tone: { anger: 0, sadness: 0, curiosity: 0.1, dryness: 0.9, playfulness: 0, tension: 0 }
|
|
};
|
|
|
|
// Generate network graph
|
|
class Node {
|
|
constructor() {
|
|
this.x = Math.random() * canvas.width;
|
|
this.y = Math.random() * canvas.height;
|
|
this.size = 1 + Math.random() * 3;
|
|
this.connections = [];
|
|
this.lifespan = params.lifespan * 3000 + Math.random() * 2000;
|
|
this.age = 0;
|
|
this.velocity = {
|
|
x: (Math.random() - 0.5) * 0.5 * params.motion,
|
|
y: (Math.random() - 0.5) * 0.5 * params.motion
|
|
};
|
|
}
|
|
|
|
update() {
|
|
this.x += this.velocity.x;
|
|
this.y += this.velocity.y;
|
|
|
|
if (this.x < 0 || this.x > canvas.width) this.velocity.x *= -1;
|
|
if (this.y < 0 || this.y > canvas.height) this.velocity.y *= -1;
|
|
|
|
this.age += 16; // approx frame time
|
|
|
|
const pulse = params.pulse.avg + Math.sin(Date.now() * 0.001) * (params.pulse.max - params.pulse.min) * 0.5;
|
|
this.size = 1 + 2 * params.density * Math.min(1, this.age / this.lifespan) * pulse;
|
|
|
|
if (this.age > this.lifespan) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
connect(node) {
|
|
if (node === this) return;
|
|
if (this.connections.length >= 5 * params.connectedness) return;
|
|
|
|
const dist = Math.hypot(this.x - node.x, this.y - node.y);
|
|
if (dist > 200 * params.density && Math.random() > params.connectedness) return;
|
|
|
|
this.connections.push({
|
|
node,
|
|
strength: Math.random() * params.complexity,
|
|
distance: dist
|
|
});
|
|
}
|
|
}
|
|
|
|
const nodes = [];
|
|
const maxNodes = 100 + params.density * 200;
|
|
|
|
// Initialize nodes
|
|
for (let i = 0; i < maxNodes; i++) {
|
|
nodes.push(new Node());
|
|
}
|
|
|
|
// Create connections
|
|
for (let i = 0; i < nodes.length; i++) {
|
|
for (let j = i + 1; j < nodes.length; j++) {
|
|
nodes[i].connect(nodes[j]);
|
|
}
|
|
}
|
|
|
|
let time = 0;
|
|
|
|
function animate() {
|
|
ctx.fillStyle = '#0a0a0a';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
const avgEnergy = params.tone.dryness > 0.5 ? 0.3 : 0.8;
|
|
ctx.strokeStyle = `rgba(200, 200, 200, ${avgEnergy * params.motion * 0.8})`;
|
|
ctx.lineWidth = 0.5 * params.complexity;
|
|
|
|
// Update and draw nodes
|
|
for (let i = 0; i < nodes.length; i++) {
|
|
if (!nodes[i].update()) {
|
|
nodes.splice(i, 1);
|
|
i--;
|
|
continue;
|
|
}
|
|
|
|
// Draw connections
|
|
for (const conn of nodes[i].connections) {
|
|
const pulse = params.pulse.avg + Math.sin(time * 0.002) * (params.pulse.max - params.pulse.min) * 0.3;
|
|
const alpha = params.connectedness * 0.7 * Math.min(1, conn.distance / 150) * pulse;
|
|
|
|
if (alpha > 0.05) {
|
|
ctx.globalAlpha = alpha;
|
|
ctx.beginPath();
|
|
ctx.moveTo(nodes[i].x, nodes[i].y);
|
|
ctx.lineTo(conn.node.x, conn.node.y);
|
|
ctx.stroke();
|
|
}
|
|
}
|
|
|
|
// Draw node
|
|
ctx.globalAlpha = 1;
|
|
ctx.beginPath();
|
|
ctx.arc(nodes[i].x, nodes[i].y, nodes[i].size, 0, Math.PI * 2);
|
|
ctx.fillStyle = `hsl(200, 30%, ${50 + 10 * Math.sin(time * 0.001 + nodes[i].x * 0.01)}%)`;
|
|
ctx.fill();
|
|
|
|
if (params.tone.playfulness > 0) {
|
|
ctx.beginPath();
|
|
ctx.arc(nodes[i].x, nodes[i].y, nodes[i].size * 1.5, 0, Math.PI * 2);
|
|
ctx.strokeStyle = `hsla(200, 70%, 80%, ${0.2 * params.playfulness})`;
|
|
ctx.stroke();
|
|
}
|
|
}
|
|
|
|
// Add new nodes occasionally
|
|
if (Math.random() < 0.01 * params.motion) {
|
|
nodes.push(new Node());
|
|
}
|
|
|
|
// Prune old nodes
|
|
if (params.lifespan < 0.3 && Math.random() < 0.005) {
|
|
if (nodes.length > maxNodes * 0.5) {
|
|
nodes.splice(Math.floor(Math.random() * nodes.length), 1);
|
|
}
|
|
}
|
|
|
|
time += 16;
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |