holiday_lights/harrogate/src/december_21_2019.rs

62 lines
1.3 KiB
Rust

//! Golden background with twinkling lights
use super::delay;
use house::Harrogate;
use lights::rgb::Rgb;
use lights::{HardwareRgb, Lights, murmurf};
const GOLD: Rgb = Rgb(200, 200, 0);
const RED: Rgb = Rgb(0, 200, 0);
const GREEN: Rgb = Rgb(0, 200, 0);
const BLUE: Rgb = Rgb(0, 0, 200);
const PURPLE: Rgb = Rgb(160, 0, 128);
const WHITE: Rgb = Rgb(255, 255, 255);
const FULL_PORCH: usize = 150;
#[derive(Copy, Clone)]
struct Pixel {
color: Rgb,
}
impl Pixel {
const fn new() -> Pixel {
Pixel {
color: GOLD
}
}
fn tick(&mut self, mut rng: u32) {
self.color = match murmurf(&mut rng) % 8 {
0..=1 => RED,
2..=3 => GREEN,
4..=5 => BLUE,
6 => PURPLE,
7 => WHITE,
_ => GOLD,
}
}
}
#[allow(dead_code)]
#[inline(always)]
pub fn run(lights: &mut impl Lights<Pixel = HardwareRgb>) -> ! {
let mut rng = 1;
let mut pixels = [Pixel::new(); FULL_PORCH];
for pixel in pixels.iter_mut() {
pixel.tick(murmurf(&mut rng));
}
loop {
Harrogate {
porch_back: (0..FULL_PORCH).map(|_| GOLD),
porch_front: pixels.iter().map(|p| p.color)
}
.render_to(lights);
delay(300_000);
}
}