flask_gif.rs (1268B)
1 //! Writes every other frame of the flask's loop as a PNG into the directory given, in the dark 2 //! skin's colours, without opening a window: `make gif` stitches them into docs/flask.gif. 3 4 use egui::Color32; 5 6 #[path = "../src/flask.rs"] 7 #[allow(dead_code)] 8 mod flask; 9 10 fn main() { 11 let dir = std::path::PathBuf::from(std::env::args().nth(1).expect("usage: flask_gif DIR")); 12 std::fs::create_dir_all(&dir).unwrap(); 13 let (glass, liquid, bg) = ( 14 Color32::from_rgb(0xD3, 0xC6, 0xAA), 15 Color32::from_rgb(0xA7, 0xC0, 0x80), 16 Color32::from_rgb(0x2D, 0x35, 0x3B), 17 ); 18 for i in (0..flask::FRAMES).step_by(2) { 19 let svg = flask::frame_svg(i, glass, liquid, bg); 20 let tree = resvg::usvg::Tree::from_str(&svg, &resvg::usvg::Options::default()).unwrap(); 21 let (w, h) = (350, 418); 22 let mut pixmap = resvg::tiny_skia::Pixmap::new(w, h).unwrap(); 23 pixmap.fill(resvg::tiny_skia::Color::from_rgba8(bg.r(), bg.g(), bg.b(), 255)); 24 let scale = w as f32 / tree.size().width(); 25 resvg::render( 26 &tree, 27 resvg::tiny_skia::Transform::from_scale(scale, scale), 28 &mut pixmap.as_mut(), 29 ); 30 pixmap.save_png(dir.join(format!("f{i:03}.png"))).unwrap(); 31 } 32 }