Make a simple twinkle.
This commit is contained in:
parent
8a1b23ba79
commit
82a9c5696a
1 changed files with 26 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
|||
//! Golden background with twinkling lights
|
||||
use super::delay;
|
||||
use core::convert::TryInto;
|
||||
use house::Harrogate;
|
||||
use lights::rgb::Rgb;
|
||||
use lights::{HardwareRgb, Lights, murmurf};
|
||||
|
@ -16,23 +17,35 @@ const FULL_PORCH: usize = 150;
|
|||
#[derive(Copy, Clone)]
|
||||
struct Pixel {
|
||||
color: Rgb,
|
||||
delay: u16
|
||||
}
|
||||
|
||||
impl Pixel {
|
||||
const fn new() -> Pixel {
|
||||
Pixel {
|
||||
color: GOLD
|
||||
color: GOLD,
|
||||
delay: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn tick(&mut self, mut rng: u32) {
|
||||
self.color = match murmurf(&mut rng) % 8 {
|
||||
fn tick(&mut self, rng: &mut u32) {
|
||||
if self.delay > 0 {
|
||||
self.delay -= 1;
|
||||
} else {
|
||||
self.color = match murmurf(rng) % 16 {
|
||||
0..=1 => RED,
|
||||
2..=3 => GREEN,
|
||||
4..=5 => BLUE,
|
||||
6 => PURPLE,
|
||||
7 => WHITE,
|
||||
_ => GOLD,
|
||||
};
|
||||
|
||||
self.delay = if self.color == GOLD {
|
||||
(murmurf(rng) % 600 + 300).try_into().unwrap_or(1000)
|
||||
} else {
|
||||
(murmurf(rng) % 100 + 50).try_into().unwrap_or(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,11 +57,10 @@ 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 {
|
||||
for pixel in pixels.iter_mut() {
|
||||
pixel.tick(&mut rng);
|
||||
}
|
||||
|
||||
Harrogate {
|
||||
porch_back: (0..FULL_PORCH).map(|_| GOLD),
|
||||
|
@ -56,6 +68,6 @@ pub fn run(lights: &mut impl Lights<Pixel = HardwareRgb>) -> ! {
|
|||
}
|
||||
.render_to(lights);
|
||||
|
||||
delay(300_000);
|
||||
delay(5_000_000 / 60);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue