From f8b6f5cc02c7a14487a4b97a3ad7f0a9e5819562 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Tue, 28 Apr 2020 17:46:23 +0200 Subject: [PATCH] Effect Matrix * Better colors --- include/effect_matrix.h | 17 +++++++++++++++++ src/effect_matrix.cpp | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/effect_matrix.h b/include/effect_matrix.h index 5ba9990..fbe2e53 100644 --- a/include/effect_matrix.h +++ b/include/effect_matrix.h @@ -48,6 +48,15 @@ public: RandomMatrixEffectColumn(Window* win, uint8_t dir, bool rnd=false) : MatrixEffectColumn(win, dir, rnd) {}; }; +class ColumnMatrixEffectColumn : public MatrixEffectColumn { +protected: + uint8_t _hue; + CRGB _getColor(uint8_t height) override; + void restart(bool completely_random) override; +public: + ColumnMatrixEffectColumn(Window* win, uint8_t dir, bool rnd=false) : MatrixEffectColumn(win, dir, rnd) {}; +}; + class MatrixEffectBase : public Effect { protected: MatrixEffectColumn** _columns; @@ -86,3 +95,11 @@ public: RandomMatrixEffect(); String get_name() override { return "random_matrix"; } }; + +class ColumnMatrixEffect : public MatrixEffectBase { +protected: + void _create() override; +public: + ColumnMatrixEffect(); + String get_name() override { return "column_matrix"; } +}; \ No newline at end of file diff --git a/src/effect_matrix.cpp b/src/effect_matrix.cpp index e602b2d..75e4976 100644 --- a/src/effect_matrix.cpp +++ b/src/effect_matrix.cpp @@ -127,6 +127,18 @@ void RandomMatrixEffectColumn::restart(bool completely_random) { _hue = random8(); } +CRGB ColumnMatrixEffectColumn::_getColor(uint8_t i) { + CRGB color; + uint8_t dist = abs(length / 2 - i); + color = CHSV(_hue, 255, 255 - dist * 5); + return color; +} + +void ColumnMatrixEffectColumn::restart(bool completely_random) { + MatrixEffectColumn::restart(completely_random); + _hue = random8(); +} + @@ -174,6 +186,15 @@ void RainbowMatrixEffect::_create() { for (int i=0; i<_count; i++) _columns[i] = new RainbowMatrixEffectColumn(window, MatrixEffectColumn::DIR_SOUTH); } +ColumnMatrixEffect::ColumnMatrixEffect() { + _init(); + _create(); +} + +void ColumnMatrixEffect::_create() { + for (int i=0; i<_count; i++) _columns[i] = new ColumnMatrixEffectColumn(window, MatrixEffectColumn::DIR_NORTH); +} + MatrixEffectBase::~MatrixEffectBase() { _delete(); }