Guide · 07 of 15
Circuits
A scene circuit is a circuit diagram that actually conducts. Parts sit between two grid points and join wherever their ends meet, so a closed loop of parts is a working circuit. It is solved again after every change: wire colour shows potential (red high, blue low, grey for anything cut off), beads move along every part at a speed set by its current (so they slow down in a branch that carries less and stop in one that carries nothing), lamps fill with the power they take, and meters read live values (in mA or mV when the value is small) with an arrow for a few seconds when a value just went up or down.
Every named part gives you its readings to use in labels, goals and the scene beside it: I_R1 is the current through R1, V_R1 the voltage across it and P_R1 its power, all positive. A node a gives V_a, its potential above the battery's - terminal. With one battery you also get Req, the resistance the battery sees (a figure drawn with emf: 0 still reads it), and short is true while something shorts an ideal battery; the same two come as Req_B and short_B for a battery named B. Readings are worked out, so they can be read but never set.
The compiler checks the wiring: every end has to meet another part, a part that ends in the middle of a wire is an error (split the wire there) unless the two are never on together, which it works out from show: conditions on a bool or a choice (so a picker can swap between any number of layouts that overlap), and the circuit needs a battery.
circuit#
The space is drawn to scale with no axes or grid, so x: and y: just frame the drawing; leave a unit of room around the parts for labels. A scene plane beside it on the same slide can read its readings, which is how a circuit drives a live graph. Put the circuit first (or the circuits, see two circuits). Add probe and the student can tap any two points to read the voltage between them, signed, red lead first.
scene circuit { x: [min, max] y: [min, max] ... }
| prop | type | description |
|---|---|---|
| probe | flag | a two-point voltmeter the student taps |
| height | flag | adds a flat | height toggle: the same circuit with potential as height, the battery lifting charge and each resistor dropping it. Drag to turn it |
| carriers | conventional | electrons | both, or a choice | what the beads stand for, see carriers |
Example
two circuits#
A slide can hold any number of circuits, side by side (two in a row) or stacked, with a worked example beside the student's own. Each is solved on its own, but they share one state like any scenes on a slide, so a param of the same name drives both. Every part id has to be unique across the slide, which keeps I_R1 and V_R1 unambiguous, and every reading from every circuit is in scope for the scenes after them, for labels, goals and reading:. Put all the circuits before any other scene. Req and short are per circuit, so with two or more circuits write Req_B and short_B for the battery B; each circuit needs exactly one battery for that.
slide { scene circuit { ... } scene circuit { ... } }
Example
carriers#
Beads show the conventional current by default: out of the + terminal, round the circuit, and back through the battery from - to +. carriers: electrons draws the electrons instead, in the charge colour, drifting the opposite way everywhere, inside the battery too. both draws the two streams side by side so the student sees they are one flow described two ways. Give it the name of a choice whose options are those words and a picker flips the view live. Readings do not change: I_R is the same current either way.
carriers: conventional | electrons | both | <choice>
Example
part label#
A part's label: is plain text, unless it starts and ends with $: then it is TeX, so a subscript works ("$R_{cd}$"). A TeX label sits where a plain one would, on the side with room.
label: "text" | "$tex$"
Example
inner#
The solver always counts rin:, but the cell is drawn ideal. inner draws it the way the book does: a dashed box round the cell with a small resistor labelled r beside it, moving with the part. inner: shown follows a bool, so a toggle can open the cell up. It needs rin:.
battery <id> = (x1, y1) -> (x2, y2) { emf: <expr>, rin: <expr>, inner[: <bool>] }
Example
battery#
The arrow points at the + terminal, the long plate. rin: is the internal resistance; without it the battery is ideal, and a wire straight across it is a short. inner draws that resistance the way the book does, a dashed box round the cell with a small resistor labelled r inside it; inner: <bool> follows a state bool, so a toggle can show it, and it needs rin:. signs writes + and - beside the plates, for a student who has not learned which plate is which. A battery cannot be flipped by a negative emf:; draw two batteries the two ways round and pick one with show:.
battery <id> = (x1, y1) -> (x2, y2) { emf: <expr>, [rin: <expr>] }
| prop | type | description |
|---|---|---|
| emf* | expr | volts |
| rin | expr | internal resistance in ohms |
| inner | flag or bool | draw the internal resistance: a dashed box round the cell with r inside. needs rin: |
| signs | flag | mark the terminals + and - |
| label | string | text beside it, ${} interpolates |
Example
resistor#
ohm: can use state, so a slider changes the resistance live.
resistor <id> = (x1, y1) -> (x2, y2) { ohm: <expr> }
| prop | type | description |
|---|---|---|
| ohm* | expr | resistance |
| label | string | text beside it |
Example
lamp#
A lamp is a resistor that shows its power as a fill. By default the brightest lamp at the start is full, so dimming and brightening read as changes from there; full: fixes the power that counts as fully lit.
lamp <id> = (x1, y1) -> (x2, y2) { ohm: <expr>, [full: <watts>] }
| prop | type | description |
|---|---|---|
| ohm* | expr | resistance |
| full | number | watts at full brightness |
Example
rheostat#
A variable resistor, drawn with the arrow. Bind ohm: to a param and add a slider.
rheostat <id> = (x1, y1) -> (x2, y2) { ohm: <expr> }
| prop | type | description |
|---|---|---|
| ohm* | expr | resistance |
Example
switch#
Give closed: a bool and the student can tap the switch to flip it. A constant or an expression makes a switch the student cannot touch.
switch <id> = (x1, y1) -> (x2, y2) { closed: <bool | expr> }
| prop | type | description |
|---|---|---|
| closed* | bool or expr | whether it conducts |
Example
switch2#
A two-way switch, drawn the way the book does it: a lever on a common terminal that rests on one of two contacts. The path has the pivot in the middle, so the first and last points are the two throws. to: picks the throw: false is the first point, true the last. Give to: a bool and the student can tap the lever to flip it; an expression makes it a switch the student cannot touch. I_<id> is the current through the lever. Without open: a switch2 is always on one throw or the other. open: is a bool or expression, and while it is true the lever rests midway between the throws and touches neither, so no current flows through it; open: wins over to:, and tapping still flips only to:.
switch2 <id> = (x1, y1) -> (x2, y2) -> (x3, y3) { to: <bool | expr>, [open: <bool | expr>] }
| prop | type | description |
|---|---|---|
| to* | bool or expr | false rests the lever on the first point, true on the last |
| open | bool or expr | while true the lever rests midway, on neither throw, and nothing flows |
Example
wire#
A wire can bend through any number of points. It needs no name; name a straight piece if you want its current, like I_w. In a scene magnet a wire is a source of magnetic field: one point is a long straight wire going through the page, flow: saying whether its current runs in or out; two points are a long wire lying in the page, its current running from the first to the second. I: is in amps.
wire [<id> =] (x1, y1) -> (x2, y2) [-> (x3, y3) ...] in a scene magnet: wire <id> = (x, y) { I: <expr>, flow: in | out } OR wire <id> = (x1, y1) -> (x2, y2) { I: <expr> }
| prop | type | description |
|---|---|---|
| I | expr | amps, a scene magnet only |
| flow | in | out | choice | a scene magnet only: which way a one-point wire carries its current through the page |
Example
ammeter#
An ideal ammeter: no resistance, and its reading shows beside it.
ammeter <id> = (x1, y1) -> (x2, y2)
| prop | type | description |
|---|---|---|
| blind | flag | draw the meter with ? for its reading, so a question can ask what it reads |
Example
voltmeter#
An ideal voltmeter: it takes no current, so it changes nothing, and reads the voltage between its two ends. Draw it beside the part it measures with its own wires.
voltmeter <id> = (x1, y1) -> (x2, y2)
| prop | type | description |
|---|---|---|
| blind | flag | draw the meter with ? for its reading, so a question can ask what it reads |
Example
node#
Names a point where parts meet and draws it with its name, so V_a reads its potential.
node <id> = (x, y) { [label: <string>] }
Example