~irimi1/nannou-experiments

ref: f895500a3f65d857ed17e35f50508209ac60c401 nannou-experiments/fiddling/unu/src/main.rs -rw-r--r-- 1.3 KiB
f895500aManuel Groß unu: Capture frames to png files 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* https://guide.nannou.cc/tutorials/basics/draw-a-sketch.html */

use nannou::prelude::*;

fn main() {
    nannou::sketch(view).run();
}

fn view(app: &App, frame: Frame){
    // get canvas to draw on
    let draw = app.draw();

    draw.background().color(WHITE);

    for i in 0..20 {
        draw.rect()
            .x_y((-i as f32 * 100.0) + (1920.0 / 2.0), 0.0)
            .w_h(2.0 * (20.0 - i as f32), 500.0)
            .z_degrees(30.0 - (7.0 *i as f32))
            .color(BLACK);
    }

    // put everything on the frame
    draw.to_frame(app, &frame).unwrap();

    // capture the output EVERY TIME
    let file_path = captured_frame_path(app, &frame);
     app.main_window().capture_frame(file_path);
}

fn captured_frame_path(app: &App, frame: &Frame) -> std::path::PathBuf {
    // Create a path that we want to save this frame to.
    app.project_path()
        .expect("failed to locate `project_path`")
        // Capture all frames to a directory called `/<path_to_nannou>/nannou/simple_capture`.
        .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")
}