basic_example/
basic_example.rs

1use nannou::prelude::*;
2use nannou_webp_animation::WebpAnimation;
3
4struct Model {
5    animation: WebpAnimation,
6}
7
8fn model(app: &App) -> Model {
9    // Create a new window
10    app.new_window().view(view).build().unwrap();
11
12    // Load the WEBP animation
13    let assets = app.assets_path().expect("Failed to find assets directory");
14    let webp_path = assets.join("animation.webp"); // Place 'animation.webp' in the 'assets' directory
15
16    // Initialize the animation
17    let animation =
18        WebpAnimation::from_file(&webp_path, app).expect("Failed to load WEBP animation");
19
20    Model { animation }
21}
22
23fn update(_app: &App, model: &mut Model, _update: Update) {
24    // Update the animation
25    model.animation.update();
26}
27
28fn view(app: &App, model: &Model, frame: Frame) {
29    // Clear the frame
30    frame.clear(BLACK);
31
32    let win = app.window_rect();
33
34    // Define the rectangle where the animation will be drawn
35    let r = Rect::from_w_h(
36        model.animation.width() as f32,
37        model.animation.height() as f32,
38    )
39    .top_left_of(win);
40
41    let draw = app.draw();
42    draw.texture(model.animation.texture())
43        .xy(r.xy())
44        .wh(r.wh());
45
46    draw.to_frame(app, &frame).unwrap();
47}
48
49fn main() {
50    nannou::app(model).update(update).run();
51}