From b5c99c320b99388f66a9789c64b56bafbcd0057d Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Wed, 25 Sep 2019 06:25:16 +0200 Subject: [PATCH] Added effect sines. --- include/effect_sines.h | 32 ++++++++++++++++++++++++++++ src/effect_sines.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 include/effect_sines.h create mode 100644 src/effect_sines.cpp diff --git a/include/effect_sines.h b/include/effect_sines.h new file mode 100644 index 0000000..12e7bc0 --- /dev/null +++ b/include/effect_sines.h @@ -0,0 +1,32 @@ +#pragma once + +#include "prototypes.h" +#include "functions.h" +#include "Effect.h" + +class SinesEffectSinus { +private: + uint8_t _value; + uint8_t _frequency; + uint8_t _amplitude; + uint8_t _x; + uint8_t _step; + Window* _window; + CRGB _color; +public: + SinesEffectSinus(Window* w); + void loop(); +}; + +class SinesEffect : public Effect { +private: + SinesEffectSinus* _sinus[EFFECT_SINES_COUNT]; + uint8_t _step = 0; +public: + SinesEffect(); + ~SinesEffect(); + boolean supports_window = true; + boolean can_be_shown_with_clock(); + void loop(); +}; + diff --git a/src/effect_sines.cpp b/src/effect_sines.cpp new file mode 100644 index 0000000..69d145c --- /dev/null +++ b/src/effect_sines.cpp @@ -0,0 +1,48 @@ +#include "effect_sines.h" + +SinesEffectSinus::SinesEffectSinus(Window* w) { + _window = w; + _frequency = random8(40)+8; + _amplitude = random(5)+2; + _x = random8(_window->width); + _step = 0; + _color = CHSV(random8(), 255, 255); +} + +void SinesEffectSinus::loop() { + _value += _frequency; + if ((_value == 0 || _value==128) && random8(16)==0) { + int8_t sign = _value == 0 ? -1 : +1; + if (_x > 200) sign = -1; + else if (_x >= _window->width) sign = 1; + _amplitude = random(3)+2; + _frequency = random8(40)+8; + _color = CHSV(random8(), 255, 255); + _x = _x - sign*_amplitude; + } + uint8_t x = _x + ((sin8(_value) - 128) * _amplitude / 128); + _window->setPixel(x, 0, &_color); +} + +SinesEffect::SinesEffect() { + for (int i=0; ishift_down_and_blur(); + for (int i=0; iloop(); + } +}