From 195592f8cbb49325c978f8b39d011fd3a8e494ce Mon Sep 17 00:00:00 2001 From: annieversary Date: Sun, 15 Aug 2021 21:32:47 +0200 Subject: [PATCH] [utils] a --- Cargo.lock | 10 +++++++++- crates/spircles/Cargo.toml | 2 +- crates/spircles/src/main.rs | 29 ++--------------------------- crates/utils/Cargo.toml | 8 ++++++++ crates/utils/src/lib.rs | 1 + crates/utils/src/record.rs | 27 +++++++++++++++++++++++++++ 6 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 crates/utils/Cargo.toml create mode 100644 crates/utils/src/lib.rs create mode 100644 crates/utils/src/record.rs diff --git a/Cargo.lock b/Cargo.lock index c017b14..c99397d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2300,7 +2300,7 @@ name = "spircles" version = "0.1.0" dependencies = [ "nannou", - "once_cell", + "utils", ] [[package]] @@ -2438,6 +2438,14 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "utils" +version = "0.1.0" +dependencies = [ + "nannou", + "once_cell", +] + [[package]] name = "version_check" version = "0.9.3" diff --git a/crates/spircles/Cargo.toml b/crates/spircles/Cargo.toml index 65b6005..962360b 100644 --- a/crates/spircles/Cargo.toml +++ b/crates/spircles/Cargo.toml @@ -5,4 +5,4 @@ edition = "2018" [dependencies] nannou = "0.17" -once_cell = "1.8.0" +utils = { path = "../utils" } diff --git a/crates/spircles/src/main.rs b/crates/spircles/src/main.rs index 927ebcb..0ada802 100644 --- a/crates/spircles/src/main.rs +++ b/crates/spircles/src/main.rs @@ -1,5 +1,7 @@ use nannou::prelude::*; +use utils::record::record; + fn main() { nannou::app(model).update(update).simple_window(view).run(); } @@ -85,30 +87,3 @@ fn view(app: &App, _model: &Model, frame: Frame) { record(app, &frame); } - -use once_cell::sync::Lazy; -static RECORDING: Lazy = Lazy::new(|| { - let args: Vec = std::env::args().collect(); - args.len() > 1 && args[1] == "-record" -}); - -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 `//nannou/simple_capture`. - .join("recordings") - .join(app.exe_name().unwrap()) - // Name each file after the number of the frame. - .join(format!("{:03}", frame.nth())) - // The extension will be PNG. We also support tiff, bmp, gif, jpeg, webp and some others. - .with_extension("png"); - - println!("frame: {} {:.3}", frame.nth(), frame.nth() as f32 / 60.0); - app.main_window().capture_frame(path); -} diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml new file mode 100644 index 0000000..7590c60 --- /dev/null +++ b/crates/utils/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "utils" +version = "0.1.0" +edition = "2018" + +[dependencies] +nannou = "0.17" +once_cell = "1.8.0" diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs new file mode 100644 index 0000000..2066636 --- /dev/null +++ b/crates/utils/src/lib.rs @@ -0,0 +1 @@ +pub mod record; diff --git a/crates/utils/src/record.rs b/crates/utils/src/record.rs new file mode 100644 index 0000000..2f2b31d --- /dev/null +++ b/crates/utils/src/record.rs @@ -0,0 +1,27 @@ +use nannou::prelude::*; +use once_cell::sync::Lazy; +static RECORDING: Lazy = Lazy::new(|| { + let args: Vec = std::env::args().collect(); + args.len() > 1 && args[1] == "-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 `//nannou/simple_capture`. + .join("recordings") + .join(app.exe_name().unwrap()) + // Name each file after the number of the frame. + .join(format!("{:03}", frame.nth())) + // The extension will be PNG. We also support tiff, bmp, gif, jpeg, webp and some others. + .with_extension("png"); + + println!("frame: {} {:.3}", frame.nth(), frame.nth() as f32 / 60.0); + app.main_window().capture_frame(path); +}