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,
}
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<Rgb>,
}
impl Default for Collide {
fn default() -> Self {
Self::new(&CollideParams::default())
}
}
impl Collide {
pub fn new(params: &CollideParams) -> Self {
Self {

View File

@ -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<Rgb>,
}
impl Default for Fade {
fn default() -> Self {
Self::new(&FadeParams::default())
}
}
impl Fade {
pub fn new(params: &FadeParams) -> Self {
Self {

View File

@ -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<Rgb>,
@ -22,6 +33,11 @@ pub struct Flashing {
colors: Vec<Rgb>,
}
impl Default for Flashing {
fn default() -> Self {
Self::new(&FlashingParams::default())
}
}
impl Flashing {
pub fn new(params: &FlashingParams) -> Self {
Self {

View File

@ -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<Rgb>,
}
impl Default for MovingPixel {
fn default() -> Self {
Self::new(&MovingPixelParams::default())
}
}
impl MovingPixel {
pub fn new(params: &MovingPixelParams) -> Self {
Self {

View File

@ -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<Rgb>,
@ -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 {

View File

@ -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 {

View File

@ -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<Rgb>,
}
impl Default for Solid {
fn default() -> Self {
Self::new(&SolidParams::default())
}
}
impl Solid {
pub fn new(params: &SolidParams) -> Self {
Self {