circuit
A canvas environment holding a direct-current circuit the reader operates: components in series and parallel, or placed by hand on a grid.
circuit

#Loops, series and parallel
circuit draws a direct-current circuit and solves it. What is written in its body is one loop: each component joined to the next, and the last back to the first. The loop is drawn round a rectangle, cut into top, right, bottom and left runs in the order written.
A parallel holds branches joined between the same two points, drawn as rungs between two rails: the first on the line the group sits on, the rest inside the loop. A branch with more than one component is a series. A parallel standing alone in the body is its own circuit, branch against branch.


circuit{
cell#c{$6$ V}(emf: 6)
ammeter#a{}
parallel{
bulb#l1{$L_1$}(resistance: 10)
series{
resistor#r{$R$}(resistance: 10)
bulb#l2{$L_2$}(resistance: 10)
}
voltmeter#v{}
}
}#Placing a circuit by hand
A circuit series and parallel cannot express, such as a bridge, is placed by hand. Every component names the grid points its ends land on, from: (2, 0); to: (1, 1), x across and y down, and is drawn on the straight line between them at any angle. A lead joins two points with a bare wire. Ends that land on the same point are joined there, with a dot where three or more meet.


circuit{
cell#c{$5$ V}(from: (0, 2); to: (0, 0); emf: 5)
lead(from: (0, 0); to: (2, 0))
lead(from: (0, 2); to: (2, 2))
resistor#r1{$R_1$}(from: (2, 0); to: (1, 1); resistance: 100)
resistor#r2{$R_2$}(from: (2, 0); to: (3, 1); resistance: 200)
resistor#r3{$R_3$}(from: (1, 1); to: (2, 2); resistance: 100)
resistor#r4{$R_4$}(from: (3, 1); to: (2, 2); resistance: 200)
ammeter#g{$G$}(from: (1, 1); to: (3, 1))
}The compiler refuses a circuit that mixes the two:
- a group in a placed circuit:
A 'series' cannot be used in a circuit placed by hand — its components name their own ends with 'from:' and 'to:' - a placed component missing an end:
This circuit is placed by hand, so every component names both its ends — 'resistor' is missing 'to:'
#Components and their values
ammeter#a with neither body nor attributes does not parse as a component. Give it an empty body, ammeter#a{}: a meter's letter already names it.A component's body is its label. Its value is a number in the attribute's SI unit, with an optional prefix letter straight after it: p, n, u (micro), m, k, M, G. So resistance: 4.7k is 4700 ohms and capacitance: 100u is 100 microfarads. A value may instead be an expression in the scene's parameters, resistance: r, which a slider then moves.
cellandbattery:emf, in volts, and an internalresistance. The long plate is the positive end and faces the way the source drives the current: along the loop, or towardsto. A negative emf turns it round.resistor:resistance, in ohms, drawn as the IEC box.bulb:resistance, andrated, the voltage it glows full at.breaker:closed, a switch.ammeterandvoltmeter: ideal meters. An ammeter takes no voltage and goes in series; a voltmeter takes no current and goes in a parallel with what it measures.capacitor:capacitance, in farads, andinitial, the voltage it starts charged to.
#Meters, bulbs and live values
Every wire a current runs through is lit in the environment's colour, yellow unless written, as strongly as its share of the circuit's largest current, with the current seen flowing along it the way it runs. So is everything the current passes through: a resistor's box, an ammeter's ring, a capacitor's plates while it charges. A wire that carries nothing, such as the leads to a voltmeter, stays grey.
A bulb glows by the power it takes, full at its rated voltage, or at the circuit's whole emf when none is written. A meter writes its reading beneath its label, in amperes or volts with a prefix. Every component with an id publishes current, voltage and power, so {{#a.current}} reads the current in prose and follows the circuit as it changes. A current runs from a component's first end to its second; a voltage is the drop along that current, or a source's rise.


circuit{
cell#c{$6$ V}(emf: 6)
breaker#s{$S$}(closed: true)
bulb#l{$L$}(resistance: 10)
resistor#r{$R$}(resistance: 10)
ammeter#a{}
}#Breakers, cues and the reader
The reader opens and closes a breaker by clicking it, or by focusing it and pressing Enter or Space, and its blade swings. fixed keeps the reader's hands off a breaker only the prose should move. A !cue.to on closed moves it at a step, and one on a value changes the value:
breaker#s{$S$}(closed: false !cue.to{true}(at: 1) !cue.to{false}(at: 2))A component taken out by a cue, or hidden, leaves a gap, and the circuit is open there, as a bulb unscrewed from its holder leaves it. The reader's flips last until the step changes.
#Capacitors charging
A capacitor charges and discharges through the circuit. When a step entered forwards, a breaker the reader flips, or a slider changes the circuit, the change is shown happening: six of its slowest time constants played over three seconds, with how far it has got in circuit time read out in the footer. A millisecond membrane and a second-long flash circuit are both seen charging. A step reached by going back or by jumping lands settled, as does every change for a reader who has asked for less motion.


circuit{
cell#c{$10$ V}(emf: 10)
breaker#s{$S$}(closed: false !cue.to{true}(at: 1 + 300ms))
resistor#r{$1\,\mathrm{k}\Omega$}(resistance: 1k)
parallel{
capacitor#k{$1\,\mathrm{mF}$}(capacitance: 1m)
voltmeter#v{$V_C$}
}
}A capacitor cut off from everything keeps its charge, so where it stands depends on what happened before. Each step replays the breakers' changes in the order they fired, so a capacitor charged at one step and isolated at the next still holds its voltage, however the reader arrived.
#Attributes
titlecolourcolour: of its own.colourcoloryellowcontinuecircuit environment this one continues: continue: #that-environment. Nothing of the circuit carries: its breakers start where this environment's own closed:s put them.#Allowed content
#Allowed in
#Examples


circuit{
cell#c{$6$ V}(emf: 6)
bulb#l1{$L_1$}(resistance: 10)
cue{
bulb#l2{$L_2$}(resistance: 10)
}(
out: 1 + 300ms
)
ammeter#a{}
}

circuit{
parallel{
cell#c{$6$ V, $2\,\Omega$}(emf: 6; resistance: 2)
voltmeter#v{}
}
resistor#r{$4\,\Omega$}(resistance: 4)
ammeter#a{}
}#Notes
- What the body holds is one loop: each component joined to the next, and the last back to the first. A
parallelstanding alone is its own circuit. - A circuit placed by hand names every component's ends with
from:andto:and joins points withleads; it cannot also useseriesorparallel. - The circuit is solved whenever anything changes, and every wire a current runs through is lit, with the current seen flowing along it.
- A capacitor's charging is shown happening, slowed so its time constant can be seen.
#Writing guidance
- Selecting canvas content — A mark belongs on the canvas when seeing it changes what the reader understands, and the detail holds as a picture on its own.