Complete pattern refactor

This commit is contained in:
Austen Adler 2021-08-21 14:11:19 -04:00
parent 5b5343dc9f
commit 1734dbb5c9
7 changed files with 102 additions and 1 deletions

View File

@ -11,6 +11,17 @@ pub struct CollideParams {
pub conjoined_color: Rgb, pub conjoined_color: Rgb,
} }
impl Default for CollideParams {
fn default() -> Self {
// The classic red/blue/purple
Self {
left_color: Rgb(255, 0, 0),
right_color: Rgb(0, 0, 255),
conjoined_color: Rgb(255, 0, 255),
}
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Collide { pub struct Collide {
num_lights: u16, num_lights: u16,
@ -26,6 +37,11 @@ pub struct Collide {
increase_offset: bool, increase_offset: bool,
lights_buf: VecDeque<Rgb>, lights_buf: VecDeque<Rgb>,
} }
impl Default for Collide {
fn default() -> Self {
Self::new(&CollideParams::default())
}
}
impl Collide { impl Collide {
pub fn new(params: &CollideParams) -> Self { pub fn new(params: &CollideParams) -> Self {
Self { Self {

View File

@ -9,6 +9,14 @@ pub struct FadeParams {
pub color: Rgb, pub color: Rgb,
} }
impl Default for FadeParams {
fn default() -> Self {
Self {
color: color::WHITE,
}
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Fade { pub struct Fade {
color: Rgb, color: Rgb,
@ -17,6 +25,11 @@ pub struct Fade {
num_lights: u16, num_lights: u16,
lights_buf: VecDeque<Rgb>, lights_buf: VecDeque<Rgb>,
} }
impl Default for Fade {
fn default() -> Self {
Self::new(&FadeParams::default())
}
}
impl Fade { impl Fade {
pub fn new(params: &FadeParams) -> Self { pub fn new(params: &FadeParams) -> Self {
Self { Self {

View File

@ -13,6 +13,17 @@ pub struct FlashingParams {
pub tick_rate: u16, pub tick_rate: u16,
} }
impl Default for FlashingParams {
fn default() -> Self {
Self {
// Red and blue flashing
colors: vec![Rgb(255, 0, 0), Rgb(0, 0, 255)],
width: 8,
tick_rate: 10,
}
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Flashing { pub struct Flashing {
lights_buf: VecDeque<Rgb>, lights_buf: VecDeque<Rgb>,
@ -22,6 +33,11 @@ pub struct Flashing {
colors: Vec<Rgb>, colors: Vec<Rgb>,
} }
impl Default for Flashing {
fn default() -> Self {
Self::new(&FlashingParams::default())
}
}
impl Flashing { impl Flashing {
pub fn new(params: &FlashingParams) -> Self { pub fn new(params: &FlashingParams) -> Self {
Self { Self {

View File

@ -9,6 +9,14 @@ pub struct MovingPixelParams {
pub color: Rgb, pub color: Rgb,
} }
impl Default for MovingPixelParams {
fn default() -> Self {
Self {
color: color::WHITE,
}
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MovingPixel { pub struct MovingPixel {
color: Rgb, color: Rgb,
@ -17,6 +25,11 @@ pub struct MovingPixel {
lights_buf: VecDeque<Rgb>, lights_buf: VecDeque<Rgb>,
} }
impl Default for MovingPixel {
fn default() -> Self {
Self::new(&MovingPixelParams::default())
}
}
impl MovingPixel { impl MovingPixel {
pub fn new(params: &MovingPixelParams) -> Self { pub fn new(params: &MovingPixelParams) -> Self {
Self { Self {

View File

@ -12,6 +12,16 @@ pub struct MovingRainbowParams {
pub skip: u8, pub skip: u8,
} }
impl Default for MovingRainbowParams {
fn default() -> Self {
Self {
width: 8,
forward: true,
skip: 4,
}
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MovingRainbow { pub struct MovingRainbow {
lights_buf: VecDeque<Rgb>, lights_buf: VecDeque<Rgb>,
@ -19,6 +29,11 @@ pub struct MovingRainbow {
width: u8, width: u8,
forward: bool, forward: bool,
} }
impl Default for MovingRainbow {
fn default() -> Self {
Self::new(&MovingRainbowParams::default())
}
}
impl MovingRainbow { impl MovingRainbow {
pub fn new(params: &MovingRainbowParams) -> Self { pub fn new(params: &MovingRainbowParams) -> Self {
Self { Self {

View File

@ -12,6 +12,16 @@ pub struct OrbParams {
pub backoff_width: u8, pub backoff_width: u8,
} }
impl Default for OrbParams {
fn default() -> Self {
Self {
color: color::WHITE,
center_width: 8,
backoff_width: 4,
}
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Orb { pub struct Orb {
/// Buffer to manage the lights /// Buffer to manage the lights
@ -33,6 +43,11 @@ pub struct Orb {
/// Direction of the orb. This can switch if `bounces` is true /// Direction of the orb. This can switch if `bounces` is true
direction: bool, direction: bool,
} }
impl Default for Orb {
fn default() -> Self {
Self::new(&OrbParams::default())
}
}
impl Orb { impl Orb {
pub fn new(params: &OrbParams) -> Self { pub fn new(params: &OrbParams) -> Self {
Self { Self {

View File

@ -1,5 +1,5 @@
use super::Pattern; use super::Pattern;
use crate::color::Rgb; use crate::color::{self, Rgb};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::vec_deque; use std::collections::vec_deque;
use std::collections::VecDeque; use std::collections::VecDeque;
@ -9,12 +9,25 @@ pub struct SolidParams {
pub color: Rgb, pub color: Rgb,
} }
impl Default for SolidParams {
fn default() -> Self {
Self {
color: color::WHITE,
}
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Solid { pub struct Solid {
color: Rgb, color: Rgb,
has_run: bool, has_run: bool,
lights_buf: VecDeque<Rgb>, lights_buf: VecDeque<Rgb>,
} }
impl Default for Solid {
fn default() -> Self {
Self::new(&SolidParams::default())
}
}
impl Solid { impl Solid {
pub fn new(params: &SolidParams) -> Self { pub fn new(params: &SolidParams) -> Self {
Self { Self {