Add ability to split rainbow
This commit is contained in:
parent
35c9de16c2
commit
ac3507b774
@ -12,6 +12,7 @@ pub struct MovingRainbowParams {
|
||||
pub width: u8,
|
||||
pub forward: bool,
|
||||
pub skip: u8,
|
||||
pub fromcenter: bool,
|
||||
}
|
||||
|
||||
impl Default for MovingRainbowParams {
|
||||
@ -20,6 +21,7 @@ impl Default for MovingRainbowParams {
|
||||
width: 8,
|
||||
forward: true,
|
||||
skip: 4,
|
||||
fromcenter: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -30,6 +32,7 @@ impl FormRender for MovingRainbowParams {
|
||||
self.width.render("width", None),
|
||||
self.forward.render("forward", None),
|
||||
self.skip.render("skip", None),
|
||||
self.fromcenter.render("fromcenter", None),
|
||||
]
|
||||
.concat()
|
||||
}
|
||||
@ -38,9 +41,12 @@ impl FormRender for MovingRainbowParams {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MovingRainbow {
|
||||
lights_buf: VecDeque<Rgb>,
|
||||
/// The index to split, if moving from the inside out
|
||||
split_index: usize,
|
||||
skip: u8,
|
||||
width: u8,
|
||||
forward: bool,
|
||||
fromcenter: bool,
|
||||
}
|
||||
impl Default for MovingRainbow {
|
||||
fn default() -> Self {
|
||||
@ -54,6 +60,8 @@ impl MovingRainbow {
|
||||
skip: params.skip,
|
||||
width: params.width,
|
||||
forward: params.forward,
|
||||
fromcenter: params.fromcenter,
|
||||
split_index: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,6 +91,8 @@ impl Pattern for MovingRainbow {
|
||||
// Always a factor of length_factor
|
||||
let buf_length = color::min_with_factor(num_lights, length_factor)?;
|
||||
|
||||
self.split_index = (num_lights / 2_u16) as usize;
|
||||
|
||||
self.lights_buf = RAINBOW
|
||||
.iter()
|
||||
.flat_map(|&x| {
|
||||
@ -96,7 +106,13 @@ impl Pattern for MovingRainbow {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
fn get_strip(&self) -> vec_deque::Iter<Rgb> {
|
||||
self.lights_buf.iter()
|
||||
fn get_strip<'a>(&'a self) -> ColorIterator {
|
||||
if self.fromcenter {
|
||||
let tmp_iter = self.lights_buf.iter().take(self.split_index);
|
||||
let tmp_iter2 = self.lights_buf.iter().take(self.split_index).rev();
|
||||
Box::new(tmp_iter.chain(tmp_iter2))
|
||||
} else {
|
||||
Box::new(self.lights_buf.iter())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user