A continuation of ch12-experiments.html. The complete source identity, every recorded occurrence, and linked equations are on its first page.
Source transcript · continued
Download complete source text ↓1,602 lines · 44.9 KB
// ==========================================
// Event Handlers
// ==========================================
function setupEventHandlers() {
// Experiment toggles
document.querySelectorAll('[data-exp]').forEach(btn => {
btn.addEventListener('click', () => {
CONFIG.currentExp = btn.dataset.exp;
// Update toggle buttons
document.querySelectorAll('[data-exp]').forEach(b => {
b.classList.toggle('active', b.dataset.exp === CONFIG.currentExp);
});
// Update label
const labels = {
spike: 'SPIKE PROPAGATION',
phi: 'PHI OSCILLATION',
gamma: 'GAMMA BINDING',
network: 'NEURAL NETWORK'
};
document.getElementById('expLabel').textContent = labels[CONFIG.currentExp];
// Reinitialize for certain experiments
if (CONFIG.currentExp === 'phi') initWaves();
});
});
// Color mode toggles
document.querySelectorAll('[data-color]').forEach(btn => {
btn.addEventListener('click', () => {
CONFIG.colorMode = btn.dataset.color;
document.querySelectorAll('[data-color]').forEach(b => {
b.classList.toggle('active', b.dataset.color === CONFIG.colorMode);
});
});
});
// Sliders
document.getElementById('neuronCount').addEventListener('input', (e) => {
CONFIG.neuronCount = parseInt(e.target.value);
document.getElementById('neuronCountValue').textContent = CONFIG.neuronCount;
initNeurons();
});
document.getElementById('propSpeed').addEventListener('input', (e) => {
CONFIG.propSpeed = parseFloat(e.target.value);
document.getElementById('propSpeedValue').textContent = CONFIG.propSpeed.toFixed(1) + 'x';
});
document.getElementById('phiTarget').addEventListener('input', (e) => {
CONFIG.phiTarget = parseFloat(e.target.value);
document.getElementById('phiTargetValue').textContent = CONFIG.phiTarget.toFixed(3);
});
document.getElementById('gammaFreq').addEventListener('input', (e) => {
CONFIG.gammaFreq = parseInt(e.target.value);
document.getElementById('gammaFreqValue').textContent = CONFIG.gammaFreq + 'Hz';
});
// Canvas click to trigger spikes
canvas.addEventListener('click', (e) => {
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
// Find nearest neuron and fire it
let nearest = null;
let minDist = Infinity;
neurons.forEach(n => {
const dist = Math.sqrt((n.x - x) ** 2 + (n.y - y) ** 2);
if (dist < minDist) {
minDist = dist;
nearest = n;
}
});
if (nearest && minDist < 100) {
nearest.fire();
}
});
}
// ==========================================
// Initialization
// ==========================================
function initExperiments() {
initCanvas();
initWaves();
setupEventHandlers();
animate(0);
}
// Start when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {});
}
</script>
</body>
</html>