From 1734dbb5c9a97f227c016d346efd84a7703a7d81 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sat, 21 Aug 2021 14:11:19 -0400 Subject: [PATCH] Complete pattern refactor --- src/pattern/collide.rs | 16 ++++++++++++++++ src/pattern/fade.rs | 13 +++++++++++++ src/pattern/flashing.rs | 16 ++++++++++++++++ src/pattern/moving_pixel.rs | 13 +++++++++++++ src/pattern/moving_rainbow.rs | 15 +++++++++++++++ src/pattern/orb.rs | 15 +++++++++++++++ src/pattern/solid.rs | 15 ++++++++++++++- 7 files changed, 102 insertions(+), 1 deletion(-) diff --git a/src/pattern/collide.rs b/src/pattern/collide.rs index aed7e6b..4329191 100644 --- a/src/pattern/collide.rs +++ b/src/pattern/collide.rs @@ -11,6 +11,17 @@ pub struct CollideParams { 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)] pub struct Collide { num_lights: u16, @@ -26,6 +37,11 @@ pub struct Collide { increase_offset: bool, lights_buf: VecDeque, } +impl Default for Collide { + fn default() -> Self { + Self::new(&CollideParams::default()) + } +} impl Collide { pub fn new(params: &CollideParams) -> Self { Self { diff --git a/src/pattern/fade.rs b/src/pattern/fade.rs index dc8e190..a08c199 100644 --- a/src/pattern/fade.rs +++ b/src/pattern/fade.rs @@ -9,6 +9,14 @@ pub struct FadeParams { pub color: Rgb, } +impl Default for FadeParams { + fn default() -> Self { + Self { + color: color::WHITE, + } + } +} + #[derive(Clone, Debug)] pub struct Fade { color: Rgb, @@ -17,6 +25,11 @@ pub struct Fade { num_lights: u16, lights_buf: VecDeque, } +impl Default for Fade { + fn default() -> Self { + Self::new(&FadeParams::default()) + } +} impl Fade { pub fn new(params: &FadeParams) -> Self { Self { diff --git a/src/pattern/flashing.rs b/src/pattern/flashing.rs index c39c6ec..9939055 100644 --- a/src/pattern/flashing.rs +++ b/src/pattern/flashing.rs @@ -13,6 +13,17 @@ pub struct FlashingParams { 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)] pub struct Flashing { lights_buf: VecDeque, @@ -22,6 +33,11 @@ pub struct Flashing { colors: Vec, } +impl Default for Flashing { + fn default() -> Self { + Self::new(&FlashingParams::default()) + } +} impl Flashing { pub fn new(params: &FlashingParams) -> Self { Self { diff --git a/src/pattern/moving_pixel.rs b/src/pattern/moving_pixel.rs index 5ff3270..4297b8f 100644 --- a/src/pattern/moving_pixel.rs +++ b/src/pattern/moving_pixel.rs @@ -9,6 +9,14 @@ pub struct MovingPixelParams { pub color: Rgb, } +impl Default for MovingPixelParams { + fn default() -> Self { + Self { + color: color::WHITE, + } + } +} + #[derive(Clone, Debug)] pub struct MovingPixel { color: Rgb, @@ -17,6 +25,11 @@ pub struct MovingPixel { lights_buf: VecDeque, } +impl Default for MovingPixel { + fn default() -> Self { + Self::new(&MovingPixelParams::default()) + } +} impl MovingPixel { pub fn new(params: &MovingPixelParams) -> Self { Self { diff --git a/src/pattern/moving_rainbow.rs b/src/pattern/moving_rainbow.rs index f85cbc3..3e8faab 100644 --- a/src/pattern/moving_rainbow.rs +++ b/src/pattern/moving_rainbow.rs @@ -12,6 +12,16 @@ pub struct MovingRainbowParams { pub skip: u8, } +impl Default for MovingRainbowParams { + fn default() -> Self { + Self { + width: 8, + forward: true, + skip: 4, + } + } +} + #[derive(Clone, Debug)] pub struct MovingRainbow { lights_buf: VecDeque, @@ -19,6 +29,11 @@ pub struct MovingRainbow { width: u8, forward: bool, } +impl Default for MovingRainbow { + fn default() -> Self { + Self::new(&MovingRainbowParams::default()) + } +} impl MovingRainbow { pub fn new(params: &MovingRainbowParams) -> Self { Self { diff --git a/src/pattern/orb.rs b/src/pattern/orb.rs index ce76bef..bc68fe9 100644 --- a/src/pattern/orb.rs +++ b/src/pattern/orb.rs @@ -12,6 +12,16 @@ pub struct OrbParams { pub backoff_width: u8, } +impl Default for OrbParams { + fn default() -> Self { + Self { + color: color::WHITE, + center_width: 8, + backoff_width: 4, + } + } +} + #[derive(Clone, Debug)] pub struct Orb { /// Buffer to manage the lights @@ -33,6 +43,11 @@ pub struct Orb { /// Direction of the orb. This can switch if `bounces` is true direction: bool, } +impl Default for Orb { + fn default() -> Self { + Self::new(&OrbParams::default()) + } +} impl Orb { pub fn new(params: &OrbParams) -> Self { Self { diff --git a/src/pattern/solid.rs b/src/pattern/solid.rs index f9c9138..74b0c01 100644 --- a/src/pattern/solid.rs +++ b/src/pattern/solid.rs @@ -1,5 +1,5 @@ use super::Pattern; -use crate::color::Rgb; +use crate::color::{self, Rgb}; use serde::{Deserialize, Serialize}; use std::collections::vec_deque; use std::collections::VecDeque; @@ -9,12 +9,25 @@ pub struct SolidParams { pub color: Rgb, } +impl Default for SolidParams { + fn default() -> Self { + Self { + color: color::WHITE, + } + } +} + #[derive(Clone, Debug)] pub struct Solid { color: Rgb, has_run: bool, lights_buf: VecDeque, } +impl Default for Solid { + fn default() -> Self { + Self::new(&SolidParams::default()) + } +} impl Solid { pub fn new(params: &SolidParams) -> Self { Self {