sketch-gravity/src/recording.rs

34 lines
1.0 KiB
Rust

use nannou::prelude::*;
use once_cell::sync::Lazy;
static RECORDING: Lazy<bool> = Lazy::new(|| {
let args: Vec<String> = std::env::args().collect();
args.iter().any(|s| s == "--record")
});
pub fn record(app: &App, frame: &Frame) {
if !*RECORDING {
return;
}
// save frame
let path = app
.project_path()
.expect("failed to locate `project_path`")
// Capture all frames to a directory called `/<path_to_nannou>/nannou/simple_capture`.
.join("recordings")
// Name each file after the number of the frame.
.join(format!("{:05}", frame.nth()))
// The extension will be PNG. We also support tiff, bmp, gif, jpeg, webp and some others.
.with_extension("png");
println!("frame: {} {:.05}", frame.nth(), frame.nth() as f32 / 60.0);
app.main_window().capture_frame(path);
}
pub fn delta_t(app: &App) -> f64 {
if *RECORDING {
1.0 / 60.0
} else {
app.duration.since_prev_update.as_secs_f64()
}
}