A series circuit on a rectangular loop: a battery on the left side, a switch on the top, a
bulb on the right and a resistor on the bottom. Turn a part off (switch: false, ..) and
the wire runs on. The switch closes at on_at seconds. Then the current flows as dots out
of the battery’s long plate, clockwise, and the bulb glows. A label left empty is not drawn.
Gallery scene: Circuit.

Circuit 5 suse fframes_kit::prelude::*;
fn figure<'a>(ui: &mut Ui<'a, '_, '_>) -> Svgr<'a> { ui.show(Circuit { center: (0.0, -0.4), width: 8.0, height: 4.5, on_at: 1.4, battery_label: "9 V", enter: Some(Create::default().into()), ..ui.defaults() })}Components are plain structs. Set the fields you need and fill the rest with ..ui.defaults(): the defaults below come from the current theme (theme. values are fields of Theme).
Circuit
Section titled “Circuit”| Field | Type | Default | Description |
|---|---|---|---|
center |
(f64, f64) |
(0.0, 0.0) |
The middle of the loop, in units of ui.space. |
width |
f64 |
8.0 |
Width of the loop in units of ui.space. |
height |
f64 |
4.5 |
Height of the loop in units of ui.space. |
battery |
bool |
true |
Draws the battery on the left side; off leaves the wire running on. |
switch |
bool |
true |
Draws the switch on the top side; off leaves the wire running on and the current starts at on_at. |
bulb |
bool |
true |
Draws the bulb on the right side; off leaves the wire running on. |
resistor |
bool |
true |
Draws the resistor on the bottom side; off leaves the wire running on. |
on_at |
f32 |
1.0 |
Seconds after the local start when the switch begins to close and the current starts. |
current_speed |
f32 |
160.0 |
Speed of the current dots along the wire, in pixels per second. |
dots |
usize |
28 |
Number of dots that make up the current, spread evenly around the loop. |
battery_label |
&str |
"9 V" |
Text beside the battery; empty for none. |
switch_label |
&str |
"" |
Text above the switch; empty for none. |
bulb_label |
&str |
"" |
Text beside the bulb; empty for none. |
resistor_label |
&str |
"R" |
Text below the resistor; empty for none. |
wire_color |
Color |
theme.colors.text |
Colour of the wire and the parts. |
dot_color |
Color |
theme.colors.accent |
Colour of the current dots. |
glow_color |
Color |
theme.colors.highlight |
Colour of the bulb’s glow once current flows. |
label_color |
Color |
theme.colors.text |
Colour of the labels. |
stroke_width |
f32 |
theme.stroke.regular |
Wire width in pixels; the battery’s short plate is 2.5 times as thick. |
enter |
Option<EnterAnim> |
None |
How the wire and the parts draw in; None shows them from the start. |
exit |
Option<ExitAnim> |
None |
How the wire and the parts leave at the end of the container; None stays. |
parts_enter |
Option<FadeIn> |
None |
How the labels, dots and glow fade in; None for none. |
parts_exit |
Option<FadeOut> |
None |
How the labels, dots and glow fade out before the end; None for none. |
Methods:
fn lever_angle(&self, now: f32) -> f64: The angle of the switch’s lever, from open (35°) to closed (0).fn flowing(&self, now: f32) -> f32: Seconds the current has flowed atnowseconds of local time, 0 before it starts.
Feature physics · Source
