use ruviz::animation::RecordConfig;
use ruviz::prelude::*;
use ruviz::record;
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let x: Vec<f64> = (0..200).map(|i| i as f64 * 0.05).collect();
std::fs::create_dir_all("export_output/gif").ok();
println!("Recording wave animation to export_output/gif/animation_wave.gif...");
let config = RecordConfig::new().max_resolution(1000, 600).framerate(30);
record!(
"export_output/gif/animation_wave.gif",
90, config: config,
|tick| {
let t = tick.time;
let omega = 2.0 * std::f64::consts::PI;
let y1: Vec<f64> = x.iter().map(|&xi| (xi * 2.0 - t * omega).sin()).collect();
let y2: Vec<f64> = x
.iter()
.map(|&xi| {
let wave1 = (xi * 2.0 - t * omega).sin();
let wave2 = (xi * 2.0 + t * omega).sin();
0.5 * (wave1 + wave2) })
.collect();
let y3: Vec<f64> = x
.iter()
.map(|&xi| {
let envelope = (-xi * 0.3).exp();
envelope * (xi * 3.0 - t * omega * 1.5).sin()
})
.collect();
Plot::new()
.line(&x, &y1)
.label("Traveling Wave")
.line(&x, &y2)
.label("Standing Wave")
.line(&x, &y3)
.label("Damped Wave")
.title(format!("Wave Interference (t = {:.2}s)", t))
.xlabel("Position")
.ylabel("Amplitude")
.xlim(0.0, 10.0)
.ylim(-1.5, 1.5)
.legend_position(LegendPosition::UpperRight)
}
)?;
println!("Animation saved to export_output/gif/animation_wave.gif");
println!(" - 90 frames at 30 FPS = 3 seconds");
println!(" - Resolution: 1000x750 (4:3 aspect from max_resolution)");
println!(" - Shows traveling, standing, and damped waves");
Ok(())
}