basic_example/
basic_example.rs1use nannou::prelude::*;
2use nannou_webp_animation::WebpAnimation;
3
4struct Model {
5 animation: WebpAnimation,
6}
7
8fn model(app: &App) -> Model {
9 app.new_window().view(view).build().unwrap();
11
12 let assets = app.assets_path().expect("Failed to find assets directory");
14 let webp_path = assets.join("animation.webp"); 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 model.animation.update();
26}
27
28fn view(app: &App, model: &Model, frame: Frame) {
29 frame.clear(BLACK);
31
32 let win = app.window_rect();
33
34 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}