diff --git a/build.rs b/build.rs index 56ecea4631ed54ac7c3ca7634cf74dfb023dcf7a..4aa57bec575deb314909e19aa51580ee1cc62bb5 100644 --- a/build.rs +++ b/build.rs @@ -7,8 +7,7 @@ use image::{GenericImageView, ImageReader}; fn main() { println!("cargo::rerun-if-changed=build.rs"); - handle_image("cat"); - handle_image("meow"); + handle_image("duck"); } fn handle_image(name: &str) { diff --git a/src/assets/duck.png b/src/assets/duck.png new file mode 100644 index 0000000000000000000000000000000000000000..7d2c910310b2b6e1e2cf23cd640bd74780493a4c Binary files /dev/null and b/src/assets/duck.png differ diff --git a/src/lib.rs b/src/lib.rs index ada07ff58733f4248a3aad0f7d5b1b5db943be47..b4b5ad281e3325f39b0a6e395003c9fa81849b78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,51 +1,14 @@ -use bitvec::{order::Msb0, view::BitView}; - -const WIDTH: i32 = 96; -const HEIGHT: i32 = 38; - #[no_mangle] pub extern "C" fn next_frame(frame: u16, ptr: *mut u8) -> u8 { - let out = unsafe { std::slice::from_raw_parts_mut(ptr, 456) }.view_bits_mut::<Msb0>(); + let out = unsafe { std::slice::from_raw_parts_mut(ptr, 456) }; if frame > 100 { return 1; } - let cat = include_bytes!(concat!(env!("OUT_DIR"), "/cat.bin")).view_bits::<Msb0>(); - let meow = include_bytes!(concat!(env!("OUT_DIR"), "/meow.bin")).view_bits::<Msb0>(); - - let thres = WIDTH / 4; - - let dx = (frame as i32 * 4 - thres).min(thres); - - for x in 0..96 { - for y in 0..38 { - let out_idx = index(x, y); - let in_idx = index(x - dx, y); - - out.set(out_idx, cat[in_idx]); - } - } - - if dx == thres && frame / 7 % 2 == 0 { - // make meow flash on and off every 4 frames for the remaining time - - for x in 0..96 { - for y in 0..38 { - let idx = index(x, y); + let duck = include_bytes!(concat!(env!("OUT_DIR"), "/duck.bin")); - out.set(idx, meow[idx] || out[idx]); - } - } - } + out.copy_from_slice(duck); 0 } - -fn index(x: i32, y: i32) -> usize { - if x < 0 || y < 0 || x >= WIDTH || y >= HEIGHT { - return 0; - } - - x as usize + y as usize * WIDTH as usize -}