Add 2021 Halloween pattern
This commit is contained in:
parent
6cc39d3a9b
commit
9c8de5a1fa
3 changed files with 63 additions and 0 deletions
|
@ -22,6 +22,7 @@ valentines-2020 = ["replace-default"]
|
||||||
st-patricks-day = ["replace-default"]
|
st-patricks-day = ["replace-default"]
|
||||||
july-4 = ["replace-default"]
|
july-4 = ["replace-default"]
|
||||||
halloween-2020 = ["replace-default"]
|
halloween-2020 = ["replace-default"]
|
||||||
|
halloween-2021 = ["replace-default"]
|
||||||
new-years-eve-2020 = ["replace-default"]
|
new-years-eve-2020 = ["replace-default"]
|
||||||
november-2020 = ["replace-default"]
|
november-2020 = ["replace-default"]
|
||||||
|
|
||||||
|
|
58
harrogate/src/halloween_2021.rs
Normal file
58
harrogate/src/halloween_2021.rs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
//! purple-and-green with "lightning" flashes
|
||||||
|
use super::delay;
|
||||||
|
use house::{Harrogate, PORCH_BACK_LEN, PORCH_FRONT_LEN};
|
||||||
|
use lights::{murmurf, rgb::Rgb, HardwareRgb, Lights};
|
||||||
|
|
||||||
|
const BLACK: Rgb = Rgb(0, 0, 0);
|
||||||
|
const GREEN: Rgb = Rgb(0, 255, 0);
|
||||||
|
const LIGHTNING: Rgb = Rgb(255, 200, 50);
|
||||||
|
|
||||||
|
const PURPLE: Rgb = Rgb(100, 0, 128);
|
||||||
|
|
||||||
|
// tenth of a second
|
||||||
|
const TIC: u32 = 4_800_000;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn run(lights: &mut impl Lights<Pixel = HardwareRgb>) -> ! {
|
||||||
|
let mut rng = 0xB00u32;
|
||||||
|
let mut back_buffer = [BLACK; PORCH_BACK_LEN];
|
||||||
|
|
||||||
|
let mut draw = |back_buffer: &[Rgb]| {
|
||||||
|
let front_pattern = [PURPLE].iter().cycle().cloned();
|
||||||
|
Harrogate {
|
||||||
|
porch_front: front_pattern.take(PORCH_FRONT_LEN),
|
||||||
|
porch_back: back_buffer.iter().cloned(),
|
||||||
|
}
|
||||||
|
.render_to(lights);
|
||||||
|
};
|
||||||
|
|
||||||
|
loop {
|
||||||
|
// clear
|
||||||
|
back_buffer.iter_mut().for_each(|pix| *pix = GREEN);
|
||||||
|
draw(&back_buffer);
|
||||||
|
|
||||||
|
// delay 3-15 seconds
|
||||||
|
delay(TIC * (murmurf(&mut rng) % 120 + 30));
|
||||||
|
|
||||||
|
// flash 1
|
||||||
|
back_buffer.iter_mut().for_each(|pix| *pix = BLACK);
|
||||||
|
flash(&mut rng, &mut back_buffer);
|
||||||
|
draw(&back_buffer);
|
||||||
|
delay(TIC * 2);
|
||||||
|
|
||||||
|
// flash 2
|
||||||
|
flash(&mut rng, &mut back_buffer);
|
||||||
|
draw(&back_buffer);
|
||||||
|
delay(TIC * 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flash(rng: &mut u32, back_buffer: &mut [Rgb]) {
|
||||||
|
let start = murmurf(rng) as usize % (PORCH_BACK_LEN - 20);
|
||||||
|
let len = murmurf(rng) as usize % 20 + murmurf(rng) as usize % 20 + 10;
|
||||||
|
let end = (start + len).min(PORCH_BACK_LEN);
|
||||||
|
back_buffer.as_mut()[start..end]
|
||||||
|
.iter_mut()
|
||||||
|
.for_each(|pix| *pix = LIGHTNING);
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ mod valentines_2020;
|
||||||
mod st_patricks_day;
|
mod st_patricks_day;
|
||||||
mod july_4;
|
mod july_4;
|
||||||
mod halloween_2020;
|
mod halloween_2020;
|
||||||
|
mod halloween_2021;
|
||||||
mod november_2020;
|
mod november_2020;
|
||||||
mod new_years_eve_2020;
|
mod new_years_eve_2020;
|
||||||
mod door_light;
|
mod door_light;
|
||||||
|
@ -45,6 +46,9 @@ fn main() -> ! {
|
||||||
#[cfg(feature = "halloween-2020")]
|
#[cfg(feature = "halloween-2020")]
|
||||||
halloween_2020::run(&mut lights);
|
halloween_2020::run(&mut lights);
|
||||||
|
|
||||||
|
#[cfg(feature = "halloween-2021")]
|
||||||
|
halloween_2021::run(&mut lights);
|
||||||
|
|
||||||
#[cfg(feature = "new-years-eve-2020")]
|
#[cfg(feature = "new-years-eve-2020")]
|
||||||
new_years_eve_2020::run(&mut lights);
|
new_years_eve_2020::run(&mut lights);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue