diff --git a/build.rs b/build.rs index 2e1c2ff49faa591a0677b9fcb7fbe6f3a00c1977..56ecea4631ed54ac7c3ca7634cf74dfb023dcf7a 100644 --- a/build.rs +++ b/build.rs @@ -5,10 +5,16 @@ use image::{GenericImageView, ImageReader}; // Example custom build script. fn main() { - println!("cargo::rerun-if-changed=assets/*"); println!("cargo::rerun-if-changed=build.rs"); - let img = ImageReader::open("src/assets/cat.png") + handle_image("cat"); + handle_image("meow"); +} + +fn handle_image(name: &str) { + println!("cargo::rerun-if-changed=src/assets/{name}.png"); + + let img = ImageReader::open(format!("src/assets/{name}.png")) .unwrap() .decode() .unwrap(); @@ -33,6 +39,6 @@ fn main() { let out_dir = env::var("OUT_DIR").unwrap(); - let mut f = File::create(Path::new(&out_dir).join("cat.bin")).unwrap(); + let mut f = File::create(Path::new(&out_dir).join(format!("{name}.bin"))).unwrap(); f.write_all(&out.as_raw_slice()).unwrap(); } diff --git a/src/assets/cat.png b/src/assets/cat.png index dbbbd271807ea0af13e2abc7b871f5a3fe618df8..3a6bea0ee6d2dbd8c938d53795e3e7a7845379a7 100644 Binary files a/src/assets/cat.png and b/src/assets/cat.png differ diff --git a/src/assets/meow.png b/src/assets/meow.png new file mode 100644 index 0000000000000000000000000000000000000000..b2f6a40efaa154c56adf842040100db2784b7486 Binary files /dev/null and b/src/assets/meow.png differ diff --git a/src/lib.rs b/src/lib.rs index f742757e08e662f937ae467af3820d689e5b0f44..ada07ff58733f4248a3aad0f7d5b1b5db943be47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ use bitvec::{order::Msb0, view::BitView}; -const WIDTH: usize = 96; -//const HEIGHT: usize = 38; +const WIDTH: i32 = 96; +const HEIGHT: i32 = 38; #[no_mangle] pub extern "C" fn next_frame(frame: u16, ptr: *mut u8) -> u8 { @@ -12,19 +12,40 @@ pub extern "C" fn next_frame(frame: u16, ptr: *mut u8) -> u8 { } 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 - frame as usize * 4) % WIDTH, 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); + + out.set(idx, meow[idx] || out[idx]); + } + } + } + 0 } -fn index(x: usize, y: usize) -> usize { - x + y * WIDTH +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 }