Visualizations
029 / 500

029 · Physics

Circuit Simulator

A SPICE-style solver runs a live schematic: LEDs blink, capacitors charge, current flows.

Every frame solves the circuit with modified nodal analysis: one Kirchhoff current law row per node plus one row per voltage source, reduced by Gaussian elimination dozens of times per frame. Capacitors and inductors become trapezoidal companion models, while diodes, LEDs and NPN transistors (Shockley and Ebers-Moll models) are linearized and re-solved by Newton-Raphson with SPICE-style junction limiting. Nothing is scripted: the astable blinker oscillates because each capacitor really holds the other transistor's base below zero until it recharges. Wire colour is node voltage, the dots move at the real branch current, resistors glow with I squared R, and a two-channel oscilloscope traces the waveforms.

Try it. Pick a preset (blinker, three-phase LED chaser, LC tank, bridge rectifier, blank breadboard) or press 1 to 5. Choose a part from the palette and drag between grid points to place it, click a switch to flip it, and hover any part to read its voltage, current and power. Select a part and use the wheel or +/- to change its value. Space pauses, N single-steps, [ and ] change the speed.

  • Modified nodal analysis
  • Newton-Raphson
  • Trapezoidal companion models
  • Ebers-Moll transistor

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a small electronic circuit simulator with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window and stays sharp on high-DPI screens, with a dotted grid. Parts sit between two grid points: wires, resistors, capacitors, batteries and a ground.
- Group grid points joined by wires into nodes (a union-find works well). Ground is node 0 at 0 V.
- Solve the circuit with modified nodal analysis: build a matrix with one row per node (Kirchhoff's current law) plus one row per battery (its fixed voltage), stamp each part into it, and solve with Gaussian elimination.
- Treat each capacitor, for a time step dt, as a conductance C/dt in parallel with a current source that carries its previous voltage. Re-solve every step, about 40 small steps per frame.
- Load an RC circuit: a 9 V battery charging a capacitor through a resistor. Draw wires coloured by node voltage, and show the capacitor voltage as a number.

Once that works, make it beautiful and alive:
- Animate dots along every wire and part at a speed proportional to its current, so you can see current flow and reverse.
- Add LEDs and diodes with the Shockley equation. They are nonlinear, so linearize around the current guess and repeat the solve (Newton-Raphson) until voltages stop changing. Make LEDs glow with their actual current.
- Let me pick a part from a palette and drag between grid points to place it, and click switches to flip them.
- Add a small oscilloscope that plots one node's voltage over time.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as NPN transistors and a two-transistor blinker that oscillates on its own, an inductor and an LC tank that rings, or an AC source with a bridge rectifier.
PreviousEcho State OracleA never-trained random reservoir forecasts chaos on a green phosphor oscilloscope. NextSliding Puzzle SolverIDA* with pattern databases solves the 15-puzzle in the fewest possible moves.

Related visualizations

  • PCB AnnealerAlgorithms Simulated annealing places chips on a circuit board, then a maze router lays copper.
  • Wireworld CircuitsEmergence A four-rule cellular automaton runs a six-bit counter and logic gates on a PCB.
  • Autograd CircuitMachine learning Type a formula and watch reverse-mode autodiff run on a printed circuit board.
  • LightningSimulation Branching lightning that grows from a dielectric breakdown model.
  • Action PotentialNature Hodgkin-Huxley spikes race down an axon while every ion channel opens and shuts.
  • Heart TissueSimulation Spiral waves, arrhythmia and defibrillation in a living sheet of heart muscle.
  • Oscilloscope MusicRetro A phosphor XY scope draws a 4D tesseract, knots and text from the stereo sound you hear.
  • Radiating ChargePhysics Shake an electric charge and watch light peel off its field lines at c.
  • Lights Out AlgebraMath The toggle-tile puzzle solved instantly at any size by linear algebra over GF(2).

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs