Skip to content
Snippets Groups Projects
Commit 8d02875e authored by Stephen D's avatar Stephen D
Browse files

jess duck

parent 946ed8d2
Branches duck
No related tags found
No related merge requests found
......@@ -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) {
......
src/assets/duck.png

1.05 KiB

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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment