224 lines
No EOL
7.3 KiB
HTML
224 lines
No EOL
7.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Neurameba Live Sketch</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
background: #0a0a0a;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
#attribution {
|
|
position: fixed;
|
|
bottom: 10px;
|
|
right: 10px;
|
|
color: rgba(255, 255, 255, 0.3);
|
|
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');
|
|
|
|
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.12, min: 0.9, max: 1.3 },
|
|
tone: { anger: 0.0, sadness: 0.0, curiosity: 0.8, dryness: 0.9, playfulness: 0.1, tension: 0.0 }
|
|
};
|
|
|
|
// Network graph implementation
|
|
class Node {
|
|
constructor(x, y) {
|
|
this.x = x;
|
|
this.y = y;
|
|
this.vx = Math.random() * 2 - 1;
|
|
this.vy = Math.random() * 2 - 1;
|
|
this.size = 2 + Math.random() * 3;
|
|
this.connections = [];
|
|
this.age = 0;
|
|
this.maxAge = 50 + Math.random() * 100;
|
|
this.energy = 0.8 + Math.random() * 0.4;
|
|
}
|
|
|
|
update() {
|
|
this.x += this.vx * params.motion;
|
|
this.y += this.vy * params.motion;
|
|
this.vx += (Math.random() - 0.5) * 0.1 * params.motion;
|
|
this.vy += (Math.random() - 0.5) * 0.1 * params.motion;
|
|
|
|
// Boundary bounce
|
|
if (this.x < 0 || this.x > canvas.width) this.vx *= -1;
|
|
if (this.y < 0 || this.y > canvas.height) this.vy *= -1;
|
|
|
|
this.age++;
|
|
this.energy *= 0.995;
|
|
}
|
|
|
|
draw() {
|
|
const hue = 180 + Math.sin(this.age * 0.1) * 30;
|
|
const sat = 70 + Math.sin(this.age * 0.05) * 20;
|
|
const light = 60 + (this.energy - 0.8) * 20;
|
|
|
|
// Fade out over time
|
|
const alpha = params.tone.dryness > 0.8 ? 0.7 * (this.energy / 1.2) : 1.0;
|
|
|
|
ctx.beginPath();
|
|
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
|
|
ctx.fillStyle = `hsla(${hue}, ${sat}%, ${light}%, ${alpha})`;
|
|
ctx.fill();
|
|
}
|
|
}
|
|
|
|
class Connection {
|
|
constructor(a, b) {
|
|
this.a = a;
|
|
this.b = b;
|
|
this.age = 0;
|
|
this.maxAge = 30 + Math.random() * 50;
|
|
this.thickness = 0.5 + Math.random();
|
|
}
|
|
|
|
update() {
|
|
this.age++;
|
|
this.thickness = 0.3 + (this.a.energy + this.b.energy) * 0.5;
|
|
}
|
|
|
|
draw() {
|
|
const alpha = params.tone.dryness > 0.8 ? 0.3 * ((this.a.energy + this.b.energy) / 2) : 0.5;
|
|
ctx.strokeStyle = `hsla(160, 60%, 80%, ${alpha})`;
|
|
ctx.lineWidth = this.thickness;
|
|
ctx.beginPath();
|
|
ctx.moveTo(this.a.x, this.a.y);
|
|
ctx.lineTo(this.b.x, this.b.y);
|
|
ctx.stroke();
|
|
}
|
|
|
|
isAlive() {
|
|
return this.age < this.maxAge &&
|
|
this.a.age < this.a.maxAge &&
|
|
this.b.age < this.b.maxAge &&
|
|
Math.hypot(this.a.x - this.b.x, this.a.y - this.b.y) < 150;
|
|
}
|
|
}
|
|
|
|
const nodes = [];
|
|
const connections = [];
|
|
let pulseTimer = 0;
|
|
|
|
function init() {
|
|
nodes.length = 0;
|
|
connections.length = 0;
|
|
|
|
// Create nodes
|
|
const nodeCount = Math.floor(20 + params.density * 80);
|
|
for (let i = 0; i < nodeCount; i++) {
|
|
nodes.push(new Node(
|
|
Math.random() * canvas.width,
|
|
Math.random() * canvas.height
|
|
));
|
|
}
|
|
|
|
// Create initial connections
|
|
if (params.connectedness > 0.3) {
|
|
for (let i = 0; i < nodes.length; i++) {
|
|
for (let j = i + 1; j < nodes.length; j++) {
|
|
if (Math.random() < params.connectedness) {
|
|
connections.push(new Connection(nodes[i], nodes[j]));
|
|
nodes[i].connections.push(nodes[j]);
|
|
nodes[j].connections.push(nodes[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function update() {
|
|
pulseTimer += 0.01;
|
|
const pulse = params.pulse.avg + Math.sin(pulseTimer) * (params.pulse.max - params.pulse.min) * 0.5;
|
|
|
|
// Update nodes
|
|
nodes.forEach(node => {
|
|
node.update();
|
|
node.size = 1.5 + pulse * (1.5 + Math.sin(node.age * 0.1) * 0.5);
|
|
});
|
|
|
|
// Update connections
|
|
connections.forEach(conn => {
|
|
conn.update();
|
|
});
|
|
|
|
// Remove dead connections
|
|
for (let i = connections.length - 1; i >= 0; i--) {
|
|
if (!connections[i].isAlive()) {
|
|
connections.splice(i, 1);
|
|
}
|
|
}
|
|
|
|
// Create new connections based on proximity and energy
|
|
if (params.connectedness > 0.2 && Math.random() < 0.05 * params.connectedness) {
|
|
const a = nodes[Math.floor(Math.random() * nodes.length)];
|
|
const b = nodes[Math.floor(Math.random() * nodes.length)];
|
|
|
|
if (a !== b && !connections.some(c => (c.a === a && c.b === b) || (c.a === b && c.b === a))) {
|
|
connections.push(new Connection(a, b));
|
|
a.connections.push(b);
|
|
b.connections.push(a);
|
|
}
|
|
}
|
|
|
|
// Occasionally add new nodes
|
|
if (params.density > 0.2 && Math.random() < 0.01 * pulse * params.density) {
|
|
nodes.push(new Node(
|
|
Math.random() * canvas.width,
|
|
Math.random() * canvas.height
|
|
));
|
|
}
|
|
}
|
|
|
|
function draw() {
|
|
// Fade background
|
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
// Draw connections first
|
|
connections.forEach(conn => conn.draw());
|
|
|
|
// Then draw nodes
|
|
nodes.forEach(node => node.draw());
|
|
}
|
|
|
|
function animate() {
|
|
update();
|
|
draw();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
init();
|
|
animate();
|
|
</script>
|
|
</body>
|
|
</html> |