use std::error::Error; use nannou::prelude::*; use once_cell::sync::Lazy; const FPS: f64 = 60.0; static RECORDING: Lazy = Lazy::new(|| std::env::args().any(|s| s == "--record")); pub fn dump_frame(app: &App, frame: &Frame) -> Result<(), Box> { if !*RECORDING { return Ok(()); } let path = app .project_path()? .join("frames") .join(format!("{:05}", frame.nth())) .with_extension("png"); println!("-> {:05} {:.3}", frame.nth(), absolute_t(app)); app.main_window().capture_frame(path); Ok(()) } pub fn delta_t(app: &App) -> f64 { if *RECORDING { 1.0 / FPS } else { app.duration.since_prev_update.as_secs_f64() } } pub fn absolute_t(app: &App) -> f64 { if *RECORDING { (app.elapsed_frames() as f64) / FPS } else { app.duration.since_start.as_secs_f64() } }