birth: Flickering Neural Constellations
This commit is contained in:
parent
cc02af82ce
commit
e09cd7f26d
1 changed files with 236 additions and 0 deletions
236
index.html
Normal file
236
index.html
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Neurameba Motd</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background: #0a0a0a;
|
||||
color: white;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#info {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
font-size: 10px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<div id="info">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();
|
||||
|
||||
const params = {
|
||||
motion: 0.464,
|
||||
density: 0.515,
|
||||
complexity: 0.564,
|
||||
connectedness: 0.477,
|
||||
lifespan: 0.506,
|
||||
pulse: { avg: 0.85, min: 0.30, max: 2.00 },
|
||||
tone: { anger: 0.00, sadness: 0.00, curiosity: 0.50, dryness: 0.80, playfulness: 0.10, tension: 0.00 }
|
||||
};
|
||||
|
||||
class Node {
|
||||
constructor(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.vx = 0;
|
||||
this.vy = 0;
|
||||
this.targetX = x;
|
||||
this.targetY = y;
|
||||
this.size = Math.random() * 2 + 1;
|
||||
this.connections = [];
|
||||
this.life = params.lifespan * 1000;
|
||||
this.energy = params.pulse.avg * 10;
|
||||
this.phase = Math.random() * Math.PI * 2;
|
||||
this.friction = 0.95;
|
||||
}
|
||||
|
||||
update() {
|
||||
this.x += (this.targetX - this.x) * 0.05 * params.motion;
|
||||
this.y += (this.targetY - this.y) * 0.05 * params.motion;
|
||||
|
||||
this.vx += (Math.random() - 0.5) * params.motion * 0.1;
|
||||
this.vy += (Math.random() - 0.5) * params.motion * 0.1;
|
||||
this.vx *= this.friction;
|
||||
this.vy *= this.friction;
|
||||
this.x += this.vx;
|
||||
this.y += this.vy;
|
||||
|
||||
this.x = Math.max(0, Math.min(canvas.width, this.x));
|
||||
this.y = Math.max(0, Math.min(canvas.height, this.y));
|
||||
|
||||
this.life--;
|
||||
this.size = Math.max(0.5, this.size * 0.99);
|
||||
|
||||
if (this.energy > 0) this.energy *= 0.99;
|
||||
}
|
||||
|
||||
draw() {
|
||||
const hue = 180 + Math.sin(this.phase) * 30;
|
||||
const saturation = 30 + this.energy * 0.5;
|
||||
const lightness = 60 + Math.sin(this.phase) * 10;
|
||||
const alpha = Math.min(1, this.life / 500);
|
||||
|
||||
ctx.strokeStyle = `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
|
||||
ctx.lineWidth = this.size * 0.5 * (0.5 + this.energy / 20);
|
||||
ctx.beginPath();
|
||||
ctx.arc(this.x, this.y, this.size * (0.5 + this.energy / 20), 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
|
||||
ctx.fillStyle = `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha * 0.2})`;
|
||||
ctx.beginPath();
|
||||
ctx.arc(this.x, this.y, this.size * 2, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
class Connection {
|
||||
constructor(nodeA, nodeB) {
|
||||
this.nodeA = nodeA;
|
||||
this.nodeB = nodeB;
|
||||
this.strength = 0.5 + Math.random() * 0.5;
|
||||
this.age = 0;
|
||||
}
|
||||
|
||||
update() {
|
||||
this.age++;
|
||||
}
|
||||
|
||||
draw() {
|
||||
const dx = this.nodeB.x - this.nodeA.x;
|
||||
const dy = this.nodeB.y - this.nodeA.y;
|
||||
const distance = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (distance > 100) return;
|
||||
|
||||
const energy = (this.nodeA.energy + this.nodeB.energy) / 20;
|
||||
const alpha = Math.min(0.8, this.age / 100) * energy;
|
||||
|
||||
if (alpha <= 0) return;
|
||||
|
||||
const hue = 180 + Math.sin(this.age * 0.01) * 30;
|
||||
const hue2 = hue + 60 + Math.sin(this.age * 0.02) * 20;
|
||||
const saturation = 30 + energy * 30;
|
||||
|
||||
const gradient = ctx.createLinearGradient(
|
||||
this.nodeA.x, this.nodeA.y,
|
||||
this.nodeB.x, this.nodeB.y
|
||||
);
|
||||
gradient.addColorStop(0, `hsla(${hue}, ${saturation}%, 70%, ${alpha})`);
|
||||
gradient.addColorStop(0.5, `hsla(${hue2}, ${saturation}%, 60%, ${alpha * 0.7})`);
|
||||
gradient.addColorStop(1, `hsla(${hue}, ${saturation}%, 70%, ${alpha})`);
|
||||
|
||||
ctx.strokeStyle = gradient;
|
||||
ctx.lineWidth = 0.5 + this.strength * 2 * (0.3 + energy);
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(this.nodeA.x, this.nodeA.y);
|
||||
ctx.lineTo(this.nodeB.x, this.nodeB.y);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
const nodes = [];
|
||||
const connections = [];
|
||||
const nodeCount = Math.floor(96 + Math.random() * 20);
|
||||
|
||||
function init() {
|
||||
nodes.length = 0;
|
||||
connections.length = 0;
|
||||
|
||||
for (let i = 0; i < nodeCount; i++) {
|
||||
nodes.push(new Node(
|
||||
Math.random() * canvas.width,
|
||||
Math.random() * canvas.height
|
||||
));
|
||||
}
|
||||
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
for (let j = i + 1; j < Math.min(i + 10, nodes.length); j++) {
|
||||
if (Math.random() < params.connectedness * 0.8) {
|
||||
connections.push(new Connection(nodes[i], nodes[j]));
|
||||
nodes[i].connections.push(j);
|
||||
nodes[j].connections.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function update() {
|
||||
nodes.forEach(node => node.update());
|
||||
connections.forEach(conn => conn.update());
|
||||
|
||||
nodes.forEach(node => {
|
||||
node.targetX += (Math.random() - 0.5) * 100 * params.motion;
|
||||
node.targetY += (Math.random() - 0.5) * 100 * params.motion;
|
||||
});
|
||||
|
||||
if (nodes.length < nodeCount && Math.random() < 0.02) {
|
||||
nodes.push(new Node(
|
||||
Math.random() * canvas.width,
|
||||
Math.random() * canvas.height
|
||||
));
|
||||
}
|
||||
|
||||
if (connections.length < Math.floor(67 + Math.random() * 20) && nodes.length > 1) {
|
||||
const a = Math.floor(Math.random() * nodes.length);
|
||||
const b = Math.floor(Math.random() * nodes.length);
|
||||
if (a !== b && !nodes[a].connections.includes(b)) {
|
||||
connections.push(new Connection(nodes[a], nodes[b]));
|
||||
nodes[a].connections.push(b);
|
||||
nodes[b].connections.push(a);
|
||||
}
|
||||
}
|
||||
|
||||
if (Math.random() < 0.05) {
|
||||
nodes.splice(Math.floor(Math.random() * nodes.length), 1);
|
||||
}
|
||||
}
|
||||
|
||||
function draw() {
|
||||
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
connections.forEach(conn => conn.draw());
|
||||
nodes.forEach(node => node.draw());
|
||||
}
|
||||
|
||||
let lastTime = 0;
|
||||
function animate(time) {
|
||||
const deltaTime = time - lastTime;
|
||||
lastTime = time;
|
||||
|
||||
ctx.globalCompositeOperation = 'source-over';
|
||||
ctx.fillStyle = 'rgba(5, 5, 10, 0.1)';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
update();
|
||||
draw();
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
}
|
||||
|
||||
init();
|
||||
animate();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue