Same Light, Different Turns
Try Move Light source position (left ← → right) from -120 toward the centre, keeping Wiring configuration on Aggression (cross-wired excitatory).
Observe At the opening position of -120, the right motor bar is higher and the caption says Turning LEFT (toward left). Moving the light to the centre equalises the bars.
Explain Wiring configuration routes each sensor intensity to a motor; the drawn turn angle is 35 times the right-minus-left motor value.
Calculate wheel response
Reset
Technical boundaries. The drawing assumes light intensity decreases linearly with geometric distance, with fixed gain 0.8 and inhibitory baseline 0.4. It redraws a single pose from the inputs rather than integrating a moving vehicle over time.
Same Light, Different Turns.
Watch a top-down SVG vehicle respond to a light source in real time. Drag the light position slider to see how different wiring configurations cause the vehicle to turn toward or away from the stimulus.
viewof veh_light_x = Inputs. range ([- 200 , 200 ], {value : - 120 , step : 5 , label : "Light source position (left ← → right)" })
viewof veh_wiring = Inputs. select (
["Fear (same-side excitatory)" , "Aggression (cross-wired excitatory)" , "Love (same-side inhibitory)" , "Explorer (cross-wired inhibitory)" ],
{value : "Aggression (cross-wired excitatory)" , label : "Wiring configuration" }
)
{
const W = 480 , H = 260 ;
const cx = W / 2 , cy = H / 2 + 20 ;
// Light stimulus: distance to left and right sensors
const lightX = cx + veh_light_x;
const lightY = 30 ;
const sensorSpread = 30 ;
const leftSensorX = cx - sensorSpread, rightSensorX = cx + sensorSpread;
const leftDist = Math . sqrt ((lightX - leftSensorX) ** 2 + (lightY - cy) ** 2 );
const rightDist = Math . sqrt ((lightX - rightSensorX) ** 2 + (lightY - cy) ** 2 );
const maxDist = Math . sqrt (400 ** 2 + 230 ** 2 );
const leftIntensity = Math . max (0 , 1 - leftDist / maxDist);
const rightIntensity = Math . max (0 , 1 - rightDist / maxDist);
let leftMotor = 0 , rightMotor = 0 ;
const base = 0.4 , gain = 0.8 ;
if (veh_wiring. startsWith ("Fear" )) {
leftMotor = leftIntensity * gain;
rightMotor = rightIntensity * gain;
} else if (veh_wiring. startsWith ("Aggression" )) {
leftMotor = rightIntensity * gain;
rightMotor = leftIntensity * gain;
} else if (veh_wiring. startsWith ("Love" )) {
leftMotor = Math . max (0 , base - leftIntensity * gain);
rightMotor = Math . max (0 , base - rightIntensity * gain);
} else {
leftMotor = Math . max (0 , base - rightIntensity * gain);
rightMotor = Math . max (0 , base - leftIntensity * gain);
}
const diff = rightMotor - leftMotor;
const angle = diff * 35 ;
const avgSpeed = (leftMotor + rightMotor) / 2 ;
const leftBarH = leftMotor * 80 ;
const rightBarH = rightMotor * 80 ;
const turnLabel = Math . abs (angle) < 2 ? "Straight" : (angle > 0 ? "Turning LEFT (toward left)" : "Turning RIGHT (toward right)" );
return html `<svg viewBox="0 0 ${ W} ${ H} " style="max-width: ${ W} px; width:100%; background:#f8f9fa; border-radius:8px; border:1px solid #dee2e6;">
<!-- Light source -->
<circle cx=" ${ lightX} " cy=" ${ lightY} " r="18" fill="#E67E22" opacity="0.85"/>
<text x=" ${ lightX} " y=" ${ lightY + 5 } " text-anchor="middle" font-size="11" fill="white" font-family="Arial">Light</text>
<!-- Light rays -->
<line x1=" ${ lightX} " y1=" ${ lightY + 18 } " x2=" ${ leftSensorX} " y2=" ${ cy - 25 } " stroke="#E67E22" stroke-width="1" stroke-dasharray="4,3" opacity="0.5"/>
<line x1=" ${ lightX} " y1=" ${ lightY + 18 } " x2=" ${ rightSensorX} " y2=" ${ cy - 25 } " stroke="#E67E22" stroke-width="1" stroke-dasharray="4,3" opacity="0.5"/>
<!-- Vehicle body -->
<g transform="translate( ${ cx} , ${ cy} ) rotate( ${ angle} )">
<rect x="-35" y="-22" width="70" height="44" rx="8" fill="#2C3E50" opacity="0.9"/>
<!-- Left wheel -->
<rect x="-42" y="-18" width="8" height="16" rx="2" fill="#7F8C8D"/>
<!-- Right wheel -->
<rect x="34" y="-18" width="8" height="16" rx="2" fill="#7F8C8D"/>
<!-- Left sensor -->
<circle cx="- ${ sensorSpread} " cy="-22" r="5" fill="#16A085"/>
<!-- Right sensor -->
<circle cx=" ${ sensorSpread} " cy="-22" r="5" fill="#16A085"/>
<!-- Direction arrow -->
<polygon points="0,-30 -6,-22 6,-22" fill="#3498DB" opacity=" ${ 0.3 + avgSpeed} "/>
<text x="0" y="6" text-anchor="middle" font-size="9" fill="white" font-family="Arial">Vehicle</text>
</g>
<!-- Motor speed bars -->
<rect x="30" y=" ${ 200 - leftBarH} " width="22" height=" ${ leftBarH} " rx="3" fill="#16A085" opacity="0.8"/>
<text x="41" y="218" text-anchor="middle" font-size="10" fill="#2C3E50" font-family="Arial">L: ${ (leftMotor * 100 ). toFixed (0 )} %</text>
<rect x=" ${ W - 52 } " y=" ${ 200 - rightBarH} " width="22" height=" ${ rightBarH} " rx="3" fill="#9B59B6" opacity="0.8"/>
<text x=" ${ W - 41 } " y="218" text-anchor="middle" font-size="10" fill="#2C3E50" font-family="Arial">R: ${ (rightMotor * 100 ). toFixed (0 )} %</text>
<!-- Labels -->
<text x=" ${ W / 2 } " y=" ${ H - 8 } " text-anchor="middle" font-size="12" fill="#2C3E50" font-family="Arial" font-weight="bold"> ${ turnLabel} </text>
<text x="41" y=" ${ 190 - leftBarH} " text-anchor="middle" font-size="9" fill="#7F8C8D" font-family="Arial">Left motor</text>
<text x=" ${ W - 41 } " y=" ${ 190 - rightBarH} " text-anchor="middle" font-size="9" fill="#7F8C8D" font-family="Arial">Right motor</text>
</svg>` ;
}
Back to the chapter