From 2fb676f37800d2af640d92883569fad90a5bdbd4 Mon Sep 17 00:00:00 2001 From: Stephen D <webmaster@scd31.com> Date: Sat, 22 Feb 2025 14:24:51 -0500 Subject: [PATCH] improvements to cat animation --- build.rs | 1 - src/assets/cat.png | Bin 4514 -> 4981 bytes src/lib.rs | 52 +++++++++++++++++++++++++++++++-------------- src/main.rs | 1 + 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/build.rs b/build.rs index 56ecea4..e427bf4 100644 --- a/build.rs +++ b/build.rs @@ -3,7 +3,6 @@ use std::{env, fs::File, io::Write, path::Path}; use bitvec::{order::Msb0, vec::BitVec}; use image::{GenericImageView, ImageReader}; -// Example custom build script. fn main() { println!("cargo::rerun-if-changed=build.rs"); diff --git a/src/assets/cat.png b/src/assets/cat.png index 3a6bea0ee6d2dbd8c938d53795e3e7a7845379a7..c1f9c4044f831385d1d4feeb27b5e61f4fdc4aa6 100644 GIT binary patch delta 942 zcmZ3a{8eqjFD@emLlY|?GO?J<!f09FE1FTjz`)p?>FgZf>FlgfP?VpRnUl)EP%)== zqOHea2brVs!LAd<+QkG5PXx?;vq-6LE0^mEfvnarSs%T>O=`TJUEPZxL=}8U-uUXl zqcy9WS1WMTHSFN_>(UE)^na35w*-IR?~m{9J$@&vV6xh0bCpoTvfF8DQ$>n@hHiXc zFUr&=;3%=^j83xOq)Q)U<G*u!_^Nkq^Pls7Ee~ZKOmc8g@iREQrPI74-7L5Hvt8ko zsi{+c%&9oEgj>kIDE8xz-r|#~jp=S@bJFHnc<D^r74b4D%*^yr=A#*_UQW?}ViRVW zUwCa*>9u|8^@%GMtk)@?`%EJ!;)sw+M?io(YiRwAj?1eiCn-Ar_LTqM@p}4+r4v>& zx%IJLS>Raq_d)%K-O;NpOkb+DPI7qP{kW!wv39q^>W3EhkM~`+Vr)8pVCub(*JmAg zqyDnDPt2N$ZF^()>%L`g7^hnw_%K;<_9kuCOs=C!AL`uhPhnTue&E2Y>(SNn%lRFq z?ee<Mz}|kKqEl+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z<oLn=;CHuXernQ93dVrW7u)_A1p>Q3qh{OR$F|)#0sPOvmDciC>cH$L>9v*?J_35T zfs5;wChq~4JHX(RE*X*|`DqIIJn()--;@RVZh`JKx3}g#P9K0Yb(OdQ4i15_8v<po zd%U}=y|;hQH2eDj#D{XnI_Mu|000emv(y5L0wgkFHZ?XkH!&?_G-GBhG+{7iEjeZ} zVl6aeF*r71W;8NoWo46s1*i-$H#aslGcz(cGC4JqHU@DDF;p=(Iy5jkH8Yd31|$kG zR53R?G%z|fGqc|Y5dpKd31A2opL#9>00006VoOIv00000008+zyML1`5+Dc_7AQ6I z-JxugR1zqE)=5M`RA}Dq*-H+>FbqXejM)E{&8RArq#x>l5a$jnHI?3t6Q_yH%nQE8 zRRjbO00IaA0R(^m0zd!(Ab<c6@IL|~qHMs3XpUF;4Hd9KW<CWT5iifM5HKQ~UNvCm z)|#;u!7ne`h}hTzDsLuRW4ZZUsen&ym{X;Z(Gf6g1^-S!d!$*0Rs@`#nUC+T1#R|s z1dIqq*gH1i5o@yG{fhYQE~skL#UKH#Zs|-1WeGa?Yr#RQxB`wWCxRZ>hW2K+)9XM1 ng4Ko+00IaA0R$XD_f*3j|8iAjf!;Sy00000NkvXXu0mjf_;O2) diff --git a/src/lib.rs b/src/lib.rs index ada07ff..e72d888 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,11 @@ 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) }; + out.fill(0); + let out = out.view_bits_mut::<Msb0>(); + + let frame: i32 = frame.into(); if frame > 100 { return 1; @@ -14,34 +18,50 @@ 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 thres = WIDTH / 3; - let dx = (frame as i32 * 4 - thres).min(thres); + let dx = if frame <= 10 { + frame * 6 - thres + } else if frame > 87 { + (frame - 77) * 6 - thres + } else { + if frame / 7 % 2 == 0 { + // make meow flash on and off every 7 frames for the remaining time - for x in 0..96 { - for y in 0..38 { - let out_idx = index(x, y); - let in_idx = index(x - dx, y); + for x in 0..96 { + for y in 0..38 { + let idx = index(x, y); - out.set(out_idx, cat[in_idx]); + out.set(idx, meow[idx]); + } + } } - } - if dx == thres && frame / 7 % 2 == 0 { - // make meow flash on and off every 4 frames for the remaining time + 60 - thres + }; - for x in 0..96 { - for y in 0..38 { - let idx = index(x, y); + for x in 0..96 { + for y in 0..38 { + let out_idx = index(x, y); + let in_idx = index(x - dx, y + cat_height(frame)); - out.set(idx, meow[idx] || out[idx]); - } + out.set(out_idx, cat[in_idx] || out[out_idx]); } } 0 } +fn cat_height(frame: i32) -> i32 { + match frame % 4 { + 0 => 0, + 1 => 1, + 2 => 2, + 3 => 1, + _ => unreachable!(), + } +} + fn index(x: i32, y: i32) -> usize { if x < 0 || y < 0 || x >= WIDTH || y >= HEIGHT { return 0; diff --git a/src/main.rs b/src/main.rs index 6fb8dea..aaaac7d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,7 @@ fn main() { } draw_frame(&frame); + println!("Frame: {}", i); } } -- GitLab