holiday_lights/harrogate/src/december_2019.rs

64 lines
1.8 KiB
Rust
Raw Normal View History

2019-11-23 23:55:21 +00:00
use super::delay;
use house::Harrogate;
use lights::rgb::{blend, blend_steps, linear_gradient, Rgb};
use lights::{HardwareRgb, Lights};
const OFF: Rgb = Rgb(0, 0, 0);
2019-12-03 23:08:19 +00:00
const GREEN: Rgb = Rgb(0, 200, 0);
2019-11-23 23:55:21 +00:00
const BLUE: Rgb = Rgb(0, 0, 200);
2019-12-03 23:08:19 +00:00
const PURPLE: Rgb = Rgb(160, 0, 128);
2019-11-23 23:55:21 +00:00
const WHITE: Rgb = Rgb(255, 255, 255);
2019-12-03 23:08:19 +00:00
const PULSE_LEN: usize = 200;
const SEGMENT_LEN: usize = 35;
2019-11-23 23:55:21 +00:00
const ZOOM: usize = 10;
const ZOOM_SEGMENT_LEN: usize = SEGMENT_LEN * ZOOM + ZOOM;
const HALF_PORCH: usize = 75;
const FULL_PORCH: usize = 150;
#[allow(dead_code)]
#[inline(always)]
pub fn run(lights: &mut impl Lights<Pixel = HardwareRgb>) -> ! {
2019-12-03 23:08:19 +00:00
let mut color_pulse = linear_gradient(GREEN, BLUE, PULSE_LEN)
2019-11-23 23:55:21 +00:00
.chain(linear_gradient(BLUE, PURPLE, PULSE_LEN))
2019-12-03 23:08:19 +00:00
.chain(linear_gradient(PURPLE, GREEN, PULSE_LEN))
2019-11-23 23:55:21 +00:00
.cycle();
let mut t = 0;
loop {
// advance "time" for pattern
t += 1;
if t > ZOOM_SEGMENT_LEN {
t = 0;
}
let color = color_pulse.next().unwrap_or(Rgb(255, 0, 0));
let half_pattern_func = |i| {
let x = (i * ZOOM) + t;
let x = x % ZOOM_SEGMENT_LEN;
match x {
x if x > SEGMENT_LEN * ZOOM => {
2019-11-24 00:32:24 +00:00
blend_steps(OFF, WHITE, ZOOM, x - SEGMENT_LEN * ZOOM)
2019-11-23 23:55:21 +00:00
}
2019-11-24 00:32:24 +00:00
x => blend_steps(WHITE, OFF, SEGMENT_LEN * ZOOM, x),
2019-11-23 23:55:21 +00:00
}
};
let pattern_func = |i| match i {
i if i < HALF_PORCH => half_pattern_func(i),
i => half_pattern_func(FULL_PORCH - i),
};
Harrogate {
2019-12-03 23:08:19 +00:00
porch_back: (0..FULL_PORCH).map(|_| color),
2019-11-23 23:55:21 +00:00
porch_front: (0..FULL_PORCH)
.map(pattern_func)
.map(|b| blend(color, WHITE, b)),
}
.render_to(lights);
2019-12-03 23:08:19 +00:00
delay(300_000);
2019-11-23 23:55:21 +00:00
}
}