diff --git a/include/effect_sines.h b/include/effect_sines.h index d1684d0..648edd4 100644 --- a/include/effect_sines.h +++ b/include/effect_sines.h @@ -6,13 +6,12 @@ class SinesEffectSinus { private: - uint8_t _value; - uint8_t _frequency; - uint8_t _amplitude; - uint8_t _x; - uint8_t _step; + uint16_t _frequency; + uint16_t _color_frequency; + uint16_t _amplitude; + uint16_t _x; + uint16_t _offset; Window* _window; - CRGB _color; public: SinesEffectSinus(Window* w); void loop(uint16_t ms); @@ -21,7 +20,9 @@ public: class SinesEffect : public Effect { private: SinesEffectSinus** _sinus; - uint8_t _step = 0; + uint8_t _count; + void _init(); + void _delete(); public: SinesEffect(); ~SinesEffect(); diff --git a/src/effect_sines.cpp b/src/effect_sines.cpp index 6a4255a..2c1f884 100644 --- a/src/effect_sines.cpp +++ b/src/effect_sines.cpp @@ -2,37 +2,42 @@ 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); + _frequency = random16(6<<8, 30<<8); + _color_frequency = random16(128, 2<<8); + _x = random16(1<<8, (_window->width-2)<<8); + accum88 diff = (_window->width<<8) - _x; + if (_x > diff) diff=_x; + _amplitude = random16(1<<8, diff); + _offset = random16(); } void SinesEffectSinus::loop(uint16_t ms) { - _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); + accum88 x = beatsin88(_frequency, _x-_amplitude, _x+_amplitude, _offset); + CRGB color = CHSV(beat88(_color_frequency, _offset)>>8, 255, 255); + _window->setSubPixel(x, 0, &color); } SinesEffect::SinesEffect() { - _sinus = new SinesEffectSinus*[settings.effects.sines.count]; - for (int i=0; ishift_down_and_blur(); - for (int i=0; iloop(ms); } }