pulsing-neural-constellatio.../index.html

193 lines
No EOL
6.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamical Tissue</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: #555;
font-size: 10px;
text-shadow: 0 0 5px rgba(0,0,0,0.5);
}
</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');
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Parameters inspired by the brief
const params = {
motion: 0.5,
density: 0.5,
complexity: 0.5,
connectedness: 0.5,
lifespan: 0.5,
pulseAvg: 1.08,
pulseRange: [0.95, 1.20],
tone: {
curiosity: 0.7,
dryness: 0.9,
playfulness: 0.1
}
};
// Network graph implementation
class Node {
constructor(x, y) {
this.x = x;
this.y = y;
this.vx = (Math.random() - 0.5) * 2 * params.motion;
this.vy = (Math.random() - 0.5) * 2 * params.motion;
this.size = 2 + Math.random() * 8 * params.density;
this.connections = [];
this.life = 0;
this.maxLife = 100 + Math.random() * 500 * params.lifespan;
this.color = `hsl(${200 + Math.random() * 40}, ${70 + Math.random() * 30}%, ${50 + Math.random() * 20}%)`;
}
update() {
this.x += this.vx;
this.y += this.vy;
// Boundary check
if (this.x < 0 || this.x > canvas.width) this.vx *= -1;
if (this.y < 0 || this.y > canvas.height) this.vy *= -1;
// Aging
this.life++;
if (this.life > this.maxLife) {
this.life = 0;
this.maxLife = 100 + Math.random() * 500 * params.lifespan;
}
}
connectTo(other) {
if (other === this) return false;
const dist = Math.sqrt((this.x - other.x) ** 2 + (this.y - other.y) ** 2);
if (dist > 200 && Math.random() > params.connectedness) return false;
this.connections.push({node: other, dist});
return true;
}
}
class NetworkGraph {
constructor() {
this.nodes = [];
this.createNodes();
this.createConnections();
}
createNodes() {
const count = 50 + Math.floor(params.density * 200);
for (let i = 0; i < count; i++) {
this.nodes.push(new Node(
Math.random() * canvas.width,
Math.random() * canvas.height
));
}
}
createConnections() {
// Create initial connections based on proximity
this.nodes.forEach(node => {
const nearby = this.nodes.filter(other =>
other !== node &&
Math.sqrt((node.x - other.x) ** 2 + (node.y - other.y) ** 2) < 200
);
nearby.forEach(other => node.connectTo(other));
});
// Add some random high-connected nodes
const hubs = Math.floor(params.connectedness * 5);
for (let i = 0; i < hubs; i++) {
const node = this.nodes[Math.floor(Math.random() * this.nodes.length)];
this.nodes.forEach(other => {
if (other !== node && Math.random() < 0.7) {
node.connectTo(other);
}
});
}
}
update() {
this.nodes.forEach(node => node.update());
}
draw() {
// Draw connections
ctx.strokeStyle = `rgba(100, 200, 255, ${0.3 * params.tone.dryness})`;
ctx.lineWidth = 0.5 + 1.5 * params.density;
this.nodes.forEach(node => {
node.connections.forEach(conn => {
ctx.beginPath();
ctx.moveTo(node.x, node.y);
ctx.lineTo(conn.node.x, conn.node.y);
ctx.stroke();
});
});
// Draw nodes
this.nodes.forEach(node => {
const alpha = Math.min(1, node.life / node.maxLife);
ctx.fillStyle = node.color.replace(')', `, ${alpha})`);
ctx.beginPath();
ctx.arc(node.x, node.y, node.size, 0, Math.PI * 2);
ctx.fill();
});
}
}
// Animation
const graph = new NetworkGraph();
let lastTime = 0;
let pulseTime = 0;
function animate(time) {
const deltaTime = (time - lastTime) / 1000;
lastTime = time;
// Pulse effect
pulseTime += deltaTime * params.pulseAvg;
const pulseScale = 1 + 0.1 * Math.sin(pulseTime) * (params.pulseRange[1] - params.pulseRange[0])/2;
// Clear with semi-transparent background for trail effect
ctx.fillStyle = `rgba(10, 10, 10, 0.05)`;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw graph with pulse scaling
ctx.save();
ctx.scale(pulseScale, pulseScale);
graph.update();
graph.draw();
ctx.restore();
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>