GasMotion::new(GasSetup { .. }) steps count hard balls in a box once, at 240 steps a
second: elastic collisions between equal masses and with the walls, with an optional
Heat { at, to, over } that brings the temperature to to times its start. The start
positions (a grid with jitter) and the directions come from seed. The steps use only
+ - × ÷ and √, so the same setup gives the same frames on every run and machine.
GasBox draws the particles, slow ones in slow_color and those faster than the start’s
root mean square speed in fast_color, and a thermometer with the factor T × ... Build
the motion in the video’s constructor. particles, temperature and rms_speed give the
numbers. Gallery scene: GasBox.

GasBox 7 suse fframes_kit::prelude::*;
struct Lesson { gas: GasMotion,}
impl Lesson { fn new() -> Self { let setup = GasSetup { seed: 7, count: 60, seconds: 7.0, heat: Some(Heat { at: 2.5, to: 3.0, over: 1.5 }), ..GasSetup::default() }; Self { gas: GasMotion::new(setup) } }
fn figure<'a>(&'a self, ui: &mut Ui<'a, '_, '_>) -> Svgr<'a> { ui.show(GasBox { motion: Some(&self.gas), scale: 1.4, ..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).
GasBox
Section titled “GasBox”| Field | Type | Default | Description |
|---|---|---|---|
motion |
Option<&GasMotion> |
None |
The simulated particles to draw, built once in the video’s constructor; None draws nothing. |
center |
(f64, f64) |
(0.0, 0.0) |
The middle of the box, in units of ui.space. |
scale |
f64 |
1.0 |
Units of ui.space per meter. |
delay |
f32 |
0.0 |
Seconds after the container’s start before the particles start to move. |
time_scale |
f32 |
1.0 |
Speed of the motion over local time; 2 runs twice as fast, 1 is real time. |
thermometer |
bool |
true |
Draws a bar right of the box that fills with the temperature, up to the highest one the motion reaches. |
labels |
bool |
true |
Writes the temperature factor over the start (T × 1.5) above the thermometer. |
box_color |
Color |
theme.colors.text |
Colour of the box walls and the thermometer frame and label. |
slow_color |
Color |
theme.colors.accent |
Colour of particles at or below the start’s root mean square speed. |
fast_color |
Color |
theme.colors.highlight |
Colour of faster particles and of the thermometer’s level. |
stroke_width |
f32 |
theme.stroke.regular |
Width of the box walls in pixels. |
enter |
Option<EnterAnim> |
None |
How the box and the thermometer frame draw in; None shows them from the start. |
exit |
Option<ExitAnim> |
None |
How the box and the thermometer frame leave at the end of the container; None stays. |
parts_enter |
Option<FadeIn> |
None |
How the particles and the level fade in; None for none. |
parts_exit |
Option<FadeOut> |
None |
How the particles and the level fade out before the end; None for none. |
Feature physics · Source
