[utils] a

main
annieversary 2021-08-15 21:32:47 +02:00
parent c40807fc16
commit 195592f8cb
6 changed files with 48 additions and 29 deletions

10
Cargo.lock generated
View File

@ -2300,7 +2300,7 @@ name = "spircles"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"nannou", "nannou",
"once_cell", "utils",
] ]
[[package]] [[package]]
@ -2438,6 +2438,14 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "utils"
version = "0.1.0"
dependencies = [
"nannou",
"once_cell",
]
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.3" version = "0.9.3"

View File

@ -5,4 +5,4 @@ edition = "2018"
[dependencies] [dependencies]
nannou = "0.17" nannou = "0.17"
once_cell = "1.8.0" utils = { path = "../utils" }

View File

@ -1,5 +1,7 @@
use nannou::prelude::*; use nannou::prelude::*;
use utils::record::record;
fn main() { fn main() {
nannou::app(model).update(update).simple_window(view).run(); nannou::app(model).update(update).simple_window(view).run();
} }
@ -85,30 +87,3 @@ fn view(app: &App, _model: &Model, frame: Frame) {
record(app, &frame); record(app, &frame);
} }
use once_cell::sync::Lazy;
static RECORDING: Lazy<bool> = Lazy::new(|| {
let args: Vec<String> = 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 `/<path_to_nannou>/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);
}

8
crates/utils/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "utils"
version = "0.1.0"
edition = "2018"
[dependencies]
nannou = "0.17"
once_cell = "1.8.0"

1
crates/utils/src/lib.rs Normal file
View File

@ -0,0 +1 @@
pub mod record;

View File

@ -0,0 +1,27 @@
use nannou::prelude::*;
use once_cell::sync::Lazy;
static RECORDING: Lazy<bool> = Lazy::new(|| {
let args: Vec<String> = 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 `/<path_to_nannou>/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);
}