Skip to content

Color MOSFET and op-amp by operating region#290

Open
esaruoho wants to merge 1 commit intopfalstad:devfrom
esaruoho:color-by-operating-region
Open

Color MOSFET and op-amp by operating region#290
esaruoho wants to merge 1 commit intopfalstad:devfrom
esaruoho:color-by-operating-region

Conversation

@esaruoho
Copy link
Copy Markdown

@esaruoho esaruoho commented Mar 3, 2026

Summary

  • MOSFETs display a colored channel indicator showing their operating region: gray for cutoff, blue for linear/triode, green for saturation
  • Op-amps (both ideal OpAmpElm and real OpAmpRealElm) show a colored fill when the output is saturating: red tint for positive rail clipping, blue tint for negative rail clipping
  • Feature is toggled via Other Options > Show Operating Region, persisted in localStorage, and off by default

Details

The MOSFET already tracks its operating region in the mode variable (0=cutoff, 1=linear, 2=saturation). This PR draws a wider colored line behind the channel segments to visually indicate the region. The colors are chosen to be distinct and meaningful: gray suggests no conduction, blue suggests resistive/linear behavior, and green suggests active/saturation operation.

For op-amps, the output voltage is compared against the supply rails. The ideal op-amp checks against maxOut/minOut, while the real op-amp checks against the actual supply voltages (volts[3]/volts[4]). When saturating, the triangle body is filled with a muted red or blue to indicate which rail the output is clipping to.

JFETs (JfetElm) inherit the MOSFET coloring automatically since they extend MosfetElm.

Files changed

  • CircuitElm.java — added static boolean showOperatingRegion field and showOperatingRegion() accessor
  • EditOptions.java — added "Show Operating Region" checkbox at index 14 (shifted existing options)
  • UIManager.java — initialize showOperatingRegion from localStorage on startup
  • MosfetElm.java — draw colored channel background based on mode (cutoff/linear/saturation)
  • OpAmpElm.java — fill triangle when output is near supply rails
  • OpAmpRealElm.java — fill triangle when output is near actual supply voltages

Test plan

  • Place an N-MOSFET in a circuit, verify channel shows gray when Vgs < Vth
  • Drive the MOSFET into linear region (Vds < Vgs-Vth), verify blue channel
  • Drive the MOSFET into saturation (Vds > Vgs-Vth), verify green channel
  • Verify P-MOSFET and JFET also show correct operating region colors
  • Place an op-amp with output driven to positive rail, verify red fill
  • Place an op-amp with output driven to negative rail, verify blue fill
  • Verify op-amp shows no fill during normal linear operation
  • Test with OpAmpRealElm (LM741/LM324) as well
  • Toggle "Show Operating Region" off in Other Options, verify no coloring
  • Verify option persists across page reloads via localStorage
  • Verify existing rendering (voltage colors, power colors, dots) is unaffected

Addresses sharpie7#846.

🤖 Generated with Claude Code

MOSFETs show channel color based on operating region (cutoff=gray,
linear/triode=blue, saturation=green). Op-amps show saturation
indication when output clips (positive=red, negative=blue fill).
Both ideal and real (LM741/LM324) op-amps are supported.
Toggled via Other Options > Show Operating Region (persisted in
localStorage, off by default).

Addresses sharpie7#846.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@esaruoho esaruoho force-pushed the color-by-operating-region branch from 2e8f568 to 280e4e1 Compare April 15, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant