import {escape,state} from './common.js'; import {BrainCircuitModel,circuitStages} from './brain-circuit-model.js?v=brain-circuit-47'; import {brainScene} from './brain-scene.js?v=brain-circuit-47'; import {setBrainFocus} from './brain-focus.js?v=brain-circuit-47'; export async function brainCircuit(root){ const model=new BrainCircuitModel();let selected=2,running=false,alive=true,raf,last,view=null; root.innerHTML=`
NEURONS → CIRCUITS → BRAIN LANDMARKS

Connect a firing cell to the bigger picture.

Explore six connected model neurons beside their anatomical landmarks. Select a stage to learn its role, then change the model and compare the signals that reach the output.

Six toy neurons illustrate signal transmission. Each regional label stands for a much larger, interacting system. This chain is not a complete biological pathway, and its numbers are model settings.

Model signal direction: input → relay → visual → context → plan → output.

${circuitStages.map((s,i)=>``).join('')}

Ready. Run 500 ms to establish a baseline, then change one setting and reset the trace for a fair comparison.

ANATOMICAL CORTEX · SCHEMATIC LANDMARKS

Loading the anatomical view…

SELECTED LANDMARK

In the brain

In this model

This switch controls one artificial unit. It does not simulate the effects of disabling a human brain region.

Simulated time
0 ms
Input-unit spikes
0
Output-unit spikes
0
Events in transit
0

From a cell to a system

A neuron can influence another cell through its connections. In this model, an upstream spike schedules a delayed voltage pulse for the next unit. Whether that unit fires depends on its voltage, recovery, incoming pulse, and inhibitory drive.

The first landmarks connect visual input, thalamus, and visual cortex. The later stages add a simplified seeing-to-acting story about context, planning, and motor output. Real systems contain many cells, parallel routes, and feedback connections absent here.

Try it

Record the output after a 500 ms baseline. Add inhibitory drive of 20 at Visual processing, reset, and run another 500 ms. Then restore inhibition to 0, disable that model neuron, reset, and repeat. Compare downstream spikes with upstream activity.

NEI · visual brain circuits ↗Neuronal Dynamics · synaptic transmission ↗
`; const $=s=>root.querySelector(s),params=()=>({drive:+$('#circuit-drive').value,strength:+$('#circuit-strength').value,delay:+$('#circuit-delay').value,inhibition:+$('#circuit-inhibition').value,inhibitUnit:+$('#circuit-inhibit-stage').value}); function choose(index,updateBrain=true){selected=index;const stage=circuitStages[index];root.querySelectorAll('[data-circuit-stage]').forEach((button,i)=>button.setAttribute('aria-pressed',String(i===index)));$('#circuit-part-name').textContent=stage.landmark;$('#circuit-part-role').textContent=stage.role;$('#circuit-part-model').textContent=stage.model;$('#circuit-enable').checked=model.enabled[index];if(updateBrain&&view){view.mode('inside');view.select(stage.region);} } function raster(){const canvas=$('#circuit-raster'),width=Math.max(320,Math.round(canvas.clientWidth));if(canvas.width!==width)canvas.width=width;const c=canvas.getContext('2d'),left=width<600?92:160,right=width-20,top=42,bottom=280,begin=Math.max(0,model.t-1000),span=Math.max(100,Math.min(1000,model.t));c.clearRect(0,0,width,330);c.fillStyle='#f8faf1';c.fillRect(0,0,width,330);c.font='14px sans-serif';c.fillStyle='#617857';c.fillText('Calculated model spike times',18,22); circuitStages.forEach((s,i)=>{const y=top+(i+.5)/6*(bottom-top);c.strokeStyle='#dce5d1';c.beginPath();c.moveTo(left,y);c.lineTo(right,y);c.stroke();c.fillStyle=model.enabled[i]?'#63795a':'#9e9c8c';c.textAlign='right';c.fillText(width<600?['Input','Relay','Visual','Context','Plan','Output'][i]:s.name,left-10,y+4);}); for(const event of model.events){if(event.t{const button=root.querySelector(`[data-circuit-stage="${index}"]`);button.classList.toggle('circuit-disabled',!model.enabled[index]);button.classList.toggle('circuit-firing',model.enabled[index]&&unit.spikes.length>0&&model.t-unit.spikes.at(-1)<20);$('#circuit-count-'+index).textContent=unit.count+' model spikes';$('#circuit-voltage-'+index).textContent=unit.v.toFixed(1)+' mV';});$('#circuit-time').textContent=model.t.toFixed(0)+' ms';$('#circuit-input-spikes').textContent=model.units[0].count;$('#circuit-output-spikes').textContent=model.units.at(-1).count;$('#circuit-in-transit').textContent=model.pending.length;raster();} function pause(){running=false;cancelAnimationFrame(raf);last=undefined;$('#circuit-run').textContent='Start circuit';$('#circuit-step').disabled=$('#circuit-batch').disabled=false;} function tick(now){if(!alive||!running)return;if(last!==undefined&&!document.hidden)model.step(Math.min(100,now-last)*+$('#circuit-speed').value/1000,params());last=now;draw();raf=requestAnimationFrame(tick);} $('#circuit-run').onclick=()=>{if(running){pause();$('#circuit-status').textContent='Paused at '+model.t.toFixed(0)+' simulated ms.';}else{running=true;last=undefined;$('#circuit-run').textContent='Pause circuit';$('#circuit-step').disabled=$('#circuit-batch').disabled=true;$('#circuit-status').textContent='Running six connected model neurons. Select a stage to inspect its anatomical landmark.';raf=requestAnimationFrame(tick);}}; for(const [id,duration] of [['circuit-step',10],['circuit-batch',500]])$('#'+id).onclick=()=>{model.step(duration,params());draw();$('#circuit-status').textContent=`Advanced ${duration} ms. Input: ${model.units[0].count} spikes; output: ${model.units.at(-1).count} spikes. These are toy-model events.`;}; $('#circuit-reset').onclick=()=>{pause();model.reset();draw();$('#circuit-status').textContent='Trace reset. Current parameters and enabled model stages are kept.';};$('#circuit-restore').onclick=()=>{pause();model.enabled.fill(true);model.reset();choose(selected);draw();$('#circuit-status').textContent='All model neurons restored and trace reset. Your input parameters are kept.';}; root.querySelectorAll('[data-circuit-stage]').forEach(button=>button.onclick=()=>{choose(+button.dataset.circuitStage);draw()});$('#circuit-enable').onchange=event=>{model.setEnabled(selected,event.target.checked);draw();$('#circuit-status').textContent=`${circuitStages[selected].name} model neuron ${event.target.checked?'enabled':'disabled'}. Reset the trace before making a baseline comparison.`;}; const units={drive:' mV eq.',strength:' mV / event',delay:' ms / connection',inhibition:' mV eq.'};for(const id of Object.keys(units))$('#circuit-'+id).oninput=event=>{$('#circuit-'+id+'-value').textContent=event.target.value+units[id];draw()}; $('#circuit-inside').onclick=()=>view?.mode('inside');$('#circuit-outside').onclick=()=>view?.mode('outside');$('#circuit-full-explorer').onclick=()=>setBrainFocus(circuitStages[selected].region); window.addEventListener('resize',draw);choose(selected);draw(); // Start the local model independently of WebGL. A failed anatomy renderer leaves it usable. brainScene($('#circuit-brain'),{onSelect:region=>{const index=circuitStages.findIndex(s=>s.region===region);if(index>=0){choose(index,false);draw();}else{const part=state.anatomy.find(p=>p.id===region);$('#circuit-anatomy-note').textContent=part?part.name+': '+part.biology:'Choose one of the six stages to return to the illustrated circuit.';}}}).then(scene=>{if(!alive||!root.isConnected){scene.destroy();return;}view=scene;view.mode('inside');view.opacity(.25);view.route(circuitStages.map(stage=>stage.region),false);view.select(circuitStages[selected].region);$('#circuit-anatomy-note').textContent='Select a model stage to highlight its landmark. You can also rotate the brain or click a mapped part. The connecting line is an illustration between landmarks, not a traced fiber pathway or measured activity.';}).catch(()=>{if(alive)$('#circuit-anatomy-note').textContent='The 3D view is unavailable here. The circuit, stage descriptions, and spike raster still work.';}); return()=>{alive=false;cancelAnimationFrame(raf);window.removeEventListener('resize',draw);view?.destroy()}; } export const brainCircuitActivity={id:'brain-circuit',name:'Neurons & Brain Circuits',icon:'⌁',tag:'CELLS · CONNECTIONS · BRAIN PARTS',title:'A cell fires.
A circuit carries it forward.',description:'Connect six model neurons, inspect their brain landmarks, and compare signal flow with inhibition or an interrupted model stage.',local:true,run:brainCircuit}; export const brainCircuitInstructions={goal:'Connect individual model neurons with anatomical landmarks and see how transmission depends on their connections.',steps:[['Establish a baseline','Run circuit 500 ms. Compare each model neuron’s spike count and the raster.'],['Inspect a brain part','Select a stage to highlight its brain landmark and read both the biological role and the model’s much simpler role.'],['Change one thing','Add inhibition at a chosen stage, or disable its model neuron. Reset the trace and run another 500 ms. Compare upstream activity with the output.']],controls:[['Connection strength','Voltage added when a scheduled model event arrives.'],['Transmission delay','The chosen delay for each artificial connection.'],['Enable this model neuron','Controls the selected unit only; it is not a human lesion simulation.'],['Open selected part in the full explorer','Keeps your anatomical selection when you open the 3D explorer.']]};