1use bland::{multi_panel, Figure, Marker, PanelGridOpts, Stroke};
2
3fn main() {
4 let xs: Vec<f64> = (0..=100).map(|i| i as f64 / 10.0).collect();
5 let response: Vec<f64> = xs.iter().map(|t| (-t / 4.0).exp() * t.cos()).collect();
6 let envelope: Vec<f64> = xs.iter().map(|t| (-t / 4.0).exp()).collect();
7
8 let panel_a = Figure::new()
9 .dimensions(800.0, 500.0)
10 .title("Panel A — response")
11 .xlabel("t [s]")
12 .ylabel("x(t)")
13 .line(&xs, &response, |s| s.label("x(t)"));
14
15 let panel_b = Figure::new()
16 .dimensions(800.0, 500.0)
17 .title("Panel B — envelope")
18 .xlabel("t [s]")
19 .ylabel("|x(t)|")
20 .line(&xs, &envelope, |s| {
21 s.label("envelope").stroke(Stroke::Dashed).marker(Marker::CircleOpen)
22 });
23
24 let svg = multi_panel(
25 &[panel_a, panel_b],
26 PanelGridOpts::default()
27 .columns(2)
28 .cell_size(800.0, 500.0)
29 .title("Damped oscillation — overview"),
30 );
31
32 std::fs::create_dir_all("out").expect("create out/");
33 std::fs::write("out/panels.svg", svg).expect("write svg");
34 println!("wrote out/panels.svg");
35}