A continuation of ch13-playground.html. The complete source identity, every recorded occurrence, and linked equations are on its first page.
Source transcript · continued
Download complete source text ↓1,583 lines · 44.3 KB
// Auto-stimulate
setTimeout(() => {
for (let i = 0; i < 3; i++) {
setTimeout(() => {
const x = 100 + Math.random() * (canvas.width - 200);
const y = 100 + Math.random() * (canvas.height - 200);
stimulateArea(x, y, 120);
}, i * 300);
}
}, 100);
});
document.getElementById('resetBtn').addEventListener('click', () => {
initNetwork();
});
// View modes
document.querySelectorAll('.view-mode').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.view-mode').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
viewMode = btn.dataset.mode;
});
});
// Mobile toggle
document.getElementById('mobileToggle').addEventListener('click', () => {
document.getElementById('sidebar').classList.toggle('open');
});
// ==========================================
// KEYBOARD SHORTCUTS
// ==========================================
document.addEventListener('keydown', (e) => {
switch(e.key.toLowerCase()) {
case ' ':
e.preventDefault();
document.getElementById('stimulateBtn').click();
break;
case 'r':
document.getElementById('randomizeBtn').click();
break;
case 'escape':
document.getElementById('resetBtn').click();
break;
case '1':
document.querySelector('[data-mode="network"]').click();
break;
case '2':
document.querySelector('[data-mode="activity"]').click();
break;
case '3':
document.querySelector('[data-mode="heatmap"]').click();
break;
}
});
// ==========================================
// INITIALIZE
// ==========================================
initNetwork();
animate();
// Auto-stimulate on load for visual appeal
setTimeout(() => {
stimulateArea(canvas.width / 2, canvas.height / 2, 200);
}, 500);
// Periodic random activity
setInterval(() => {
if (Math.random() < 0.1) {
const randomNeuron = neurons[Math.floor(Math.random() * neurons.length)];
if (randomNeuron && randomNeuron.refractory <= 0) {
randomNeuron.potential += 0.3;
}
}
}, 100);
</script>
</body>
</html>