Skip to main content

damped_oscillation/
damped_oscillation.rs

1use bland::{Figure, PaperSize, Stroke, TitleBlock};
2
3fn main() {
4    let xs: Vec<f64> = (0..=200).map(|i| i as f64 / 20.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 fig = Figure::new()
9        .size(PaperSize::A5Landscape)
10        .title("Damped oscillation")
11        .xlabel("t [s]")
12        .ylabel("x(t)")
13        .line(&xs, &response, |s| s.label("response"))
14        .line(&xs, &envelope, |s| s.label("envelope").stroke(Stroke::Dashed))
15        .hline(0.0, |s| s.stroke(Stroke::Dotted))
16        .legend_top_right()
17        .title_block(
18            TitleBlock::new()
19                .project("BLAND Reference")
20                .title("Fig. 1 ยท Damped oscillation")
21                .drawn_by("JM")
22                .date("2026-04-28")
23                .scale("1:1")
24                .sheet("1 of 1")
25                .rev("A"),
26        );
27
28    std::fs::create_dir_all("out").expect("create out/");
29    std::fs::write("out/damped_oscillation.svg", fig.to_svg()).expect("write svg");
30    println!("wrote out/damped_oscillation.svg");
31}