diff --git a/img/not-found.png b/img/not-found.png index d0a8296..6fb2706 100644 Binary files a/img/not-found.png and b/img/not-found.png differ diff --git a/img/seasons/face.png b/img/seasons/face.png index 5d41dc6..2345307 100644 Binary files a/img/seasons/face.png and b/img/seasons/face.png differ diff --git a/img/seasons/halloween/bat-0.png b/img/seasons/halloween/bat-0.png index c2222fb..7167b82 100644 Binary files a/img/seasons/halloween/bat-0.png and b/img/seasons/halloween/bat-0.png differ diff --git a/img/seasons/halloween/bat-1.png b/img/seasons/halloween/bat-1.png index 1e925b0..8193a82 100644 Binary files a/img/seasons/halloween/bat-1.png and b/img/seasons/halloween/bat-1.png differ diff --git a/img/seasons/halloween/bat-2.png b/img/seasons/halloween/bat-2.png index 5f983ec..82216bc 100644 Binary files a/img/seasons/halloween/bat-2.png and b/img/seasons/halloween/bat-2.png differ diff --git a/img/seasons/halloween/bat-3.png b/img/seasons/halloween/bat-3.png index 0ded422..5ee7689 100644 Binary files a/img/seasons/halloween/bat-3.png and b/img/seasons/halloween/bat-3.png differ diff --git a/img/seasons/halloween/bat-4.png b/img/seasons/halloween/bat-4.png index eb685bf..1def8fa 100644 Binary files a/img/seasons/halloween/bat-4.png and b/img/seasons/halloween/bat-4.png differ diff --git a/img/seasons/halloween/bat-5.png b/img/seasons/halloween/bat-5.png index a3778d3..6b5e6c6 100644 Binary files a/img/seasons/halloween/bat-5.png and b/img/seasons/halloween/bat-5.png differ diff --git a/img/seasons/halloween/bat-6.png b/img/seasons/halloween/bat-6.png index e0fe5f2..0d54b42 100644 Binary files a/img/seasons/halloween/bat-6.png and b/img/seasons/halloween/bat-6.png differ diff --git a/img/seasons/halloween/bat-7.png b/img/seasons/halloween/bat-7.png index 8165ae0..ed584a0 100644 Binary files a/img/seasons/halloween/bat-7.png and b/img/seasons/halloween/bat-7.png differ diff --git a/img/seasons/halloween/bat-8.png b/img/seasons/halloween/bat-8.png index 00785b3..307b377 100644 Binary files a/img/seasons/halloween/bat-8.png and b/img/seasons/halloween/bat-8.png differ diff --git a/img/wolt.png b/img/wolt.png index f7d1f4e..fdc9a0d 100644 Binary files a/img/wolt.png and b/img/wolt.png differ diff --git a/img/xkcd2.png b/img/xkcd2.png index 6375dc5..47bcbc6 100644 Binary files a/img/xkcd2.png and b/img/xkcd2.png differ diff --git a/src/seasons/halloween.rs b/src/seasons/halloween.rs index b90a1e7..a3a3ec0 100644 --- a/src/seasons/halloween.rs +++ b/src/seasons/halloween.rs @@ -1,6 +1,6 @@ -use crate::{ui::*, StaticAssets}; +use crate::ui::*; use rand::Rng; -use slint::{Image, LogicalPosition, Rgba8Pixel, SharedPixelBuffer, Timer, TimerMode}; +use slint::{LogicalPosition, Timer, TimerMode}; pub fn setup_halloween_spooky_face(main_window: &MainWindow) -> Timer { let halloween_timer = Timer::default(); @@ -44,62 +44,25 @@ pub fn setup_halloween_bat(main_window: &MainWindow) -> Timer { let timer = Timer::default(); let mut rng = rand::thread_rng(); - let frames = read_bat_frames(); let handle = main_window.as_weak(); - let mut frame_number = 0; - let mut current_pos = LogicalPosition { x: 0.0, y: 0.0 }; timer.start( TimerMode::Repeated, - std::time::Duration::from_millis(100), + std::time::Duration::from_secs(20), move || { - let frame = &frames.clone()[frame_number % 9]; + let new_pos = LogicalPosition { + x: rng.gen_range(0.0..width as f32), + y: rng.gen_range(0.0..height as f32), + }; + let bat = Bat { - frame: frame.clone(), - pos: current_pos, + pos: new_pos, size: 200 as f32, }; - if frame_number % 200 == 0 { - current_pos = LogicalPosition { - x: rng.gen_range(0.0..width as f32), - y: rng.gen_range(0.0..height as f32), - }; - } - - frame_number += 1; - handle.unwrap().set_bat(bat) }, ); timer } - -fn read_bat_frames() -> Vec { - let mut frames = vec![]; - - for i in 0..9 { - let bat_frame_path = std::format!("seasons/halloween/bat-{}.png", i); - let frame_data = match StaticAssets::get(&bat_frame_path) { - Some(icon_data) => icon_data.data.into_owned(), - None => StaticAssets::get("not-found.png") - .unwrap() - .data - .into_owned(), - }; - - let bat_frame = image::load_from_memory_with_format(&frame_data, image::ImageFormat::Png) - .unwrap() - .into_rgba8(); - - let buffer = SharedPixelBuffer::::clone_from_slice( - bat_frame.as_raw(), - bat_frame.width(), - bat_frame.height(), - ); - - frames.push(Image::from_rgba8(buffer)) - } - frames -} diff --git a/ui/seasons.slint b/ui/seasons.slint index dcbe583..eb5a4e5 100644 --- a/ui/seasons.slint +++ b/ui/seasons.slint @@ -10,8 +10,7 @@ export struct SpookyFace { export struct Bat { pos: Point, - size: length, - frame: image} + size: length} component Flake inherits Rectangle { width: 10px; @@ -40,7 +39,6 @@ export component SeasonEffects inherits Rectangle { y: spooky_face.pos.y; z: 200.0; width: spooky_face.size; - colorize: darkorange; opacity: spooky_face.hidden ? 0% : 30%; animate opacity { @@ -50,15 +48,29 @@ export component SeasonEffects inherits Rectangle { } Image { - source: bat.frame; - width: 200px; + + property <[image]> frames: [ + @image-url("../img/seasons/halloween/bat-0.png"), + @image-url("../img/seasons/halloween/bat-1.png"), + @image-url("../img/seasons/halloween/bat-2.png"), + @image-url("../img/seasons/halloween/bat-3.png"), + @image-url("../img/seasons/halloween/bat-4.png"), + @image-url("../img/seasons/halloween/bat-5.png"), + @image-url("../img/seasons/halloween/bat-6.png"), + @image-url("../img/seasons/halloween/bat-7.png"), + @image-url("../img/seasons/halloween/bat-8.png"), + ]; + property duration: 1000ms; + property total-frames: frames.length - 1; + source: frames[(total-frames * (animation-tick() / duration)).mod(total-frames)]; + x: bat.pos.x; y: bat.pos.y; z: 200; animate x, y { - duration: 2s; - easing: ease-out-bounce; + duration: 10s; + easing: ease; } } }