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 width: u8,
|
||||||
pub forward: bool,
|
pub forward: bool,
|
||||||
pub skip: u8,
|
pub skip: u8,
|
||||||
|
pub fromcenter: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MovingRainbowParams {
|
impl Default for MovingRainbowParams {
|
||||||
@ -20,6 +21,7 @@ impl Default for MovingRainbowParams {
|
|||||||
width: 8,
|
width: 8,
|
||||||
forward: true,
|
forward: true,
|
||||||
skip: 4,
|
skip: 4,
|
||||||
|
fromcenter: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,6 +32,7 @@ impl FormRender for MovingRainbowParams {
|
|||||||
self.width.render("width", None),
|
self.width.render("width", None),
|
||||||
self.forward.render("forward", None),
|
self.forward.render("forward", None),
|
||||||
self.skip.render("skip", None),
|
self.skip.render("skip", None),
|
||||||
|
self.fromcenter.render("fromcenter", None),
|
||||||
]
|
]
|
||||||
.concat()
|
.concat()
|
||||||
}
|
}
|
||||||
@ -38,9 +41,12 @@ impl FormRender for MovingRainbowParams {
|
|||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct MovingRainbow {
|
pub struct MovingRainbow {
|
||||||
lights_buf: VecDeque<Rgb>,
|
lights_buf: VecDeque<Rgb>,
|
||||||
|
/// The index to split, if moving from the inside out
|
||||||
|
split_index: usize,
|
||||||
skip: u8,
|
skip: u8,
|
||||||
width: u8,
|
width: u8,
|
||||||
forward: bool,
|
forward: bool,
|
||||||
|
fromcenter: bool,
|
||||||
}
|
}
|
||||||
impl Default for MovingRainbow {
|
impl Default for MovingRainbow {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@ -54,6 +60,8 @@ impl MovingRainbow {
|
|||||||
skip: params.skip,
|
skip: params.skip,
|
||||||
width: params.width,
|
width: params.width,
|
||||||
forward: params.forward,
|
forward: params.forward,
|
||||||
|
fromcenter: params.fromcenter,
|
||||||
|
split_index: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,6 +91,8 @@ impl Pattern for MovingRainbow {
|
|||||||
// Always a factor of length_factor
|
// Always a factor of length_factor
|
||||||
let buf_length = color::min_with_factor(num_lights, 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
|
self.lights_buf = RAINBOW
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|&x| {
|
.flat_map(|&x| {
|
||||||
@ -96,7 +106,13 @@ impl Pattern for MovingRainbow {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn get_strip(&self) -> vec_deque::Iter<Rgb> {
|
fn get_strip<'a>(&'a self) -> ColorIterator {
|
||||||
self.lights_buf.iter()
|
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