sines effect now uses subpixel rendering.

This commit is contained in:
Fabian Schlenz 2019-10-04 12:05:54 +02:00
parent 2b7033b685
commit af1314632e
2 changed files with 38 additions and 29 deletions

View File

@ -6,13 +6,12 @@
class SinesEffectSinus { class SinesEffectSinus {
private: private:
uint8_t _value; uint16_t _frequency;
uint8_t _frequency; uint16_t _color_frequency;
uint8_t _amplitude; uint16_t _amplitude;
uint8_t _x; uint16_t _x;
uint8_t _step; uint16_t _offset;
Window* _window; Window* _window;
CRGB _color;
public: public:
SinesEffectSinus(Window* w); SinesEffectSinus(Window* w);
void loop(uint16_t ms); void loop(uint16_t ms);
@ -21,7 +20,9 @@ public:
class SinesEffect : public Effect { class SinesEffect : public Effect {
private: private:
SinesEffectSinus** _sinus; SinesEffectSinus** _sinus;
uint8_t _step = 0; uint8_t _count;
void _init();
void _delete();
public: public:
SinesEffect(); SinesEffect();
~SinesEffect(); ~SinesEffect();

View File

@ -2,37 +2,42 @@
SinesEffectSinus::SinesEffectSinus(Window* w) { SinesEffectSinus::SinesEffectSinus(Window* w) {
_window = w; _window = w;
_frequency = random8(40)+8; _frequency = random16(6<<8, 30<<8);
_amplitude = random(5)+2; _color_frequency = random16(128, 2<<8);
_x = random8(_window->width); _x = random16(1<<8, (_window->width-2)<<8);
_step = 0; accum88 diff = (_window->width<<8) - _x;
_color = CHSV(random8(), 255, 255); if (_x > diff) diff=_x;
_amplitude = random16(1<<8, diff);
_offset = random16();
} }
void SinesEffectSinus::loop(uint16_t ms) { void SinesEffectSinus::loop(uint16_t ms) {
_value += _frequency; accum88 x = beatsin88(_frequency, _x-_amplitude, _x+_amplitude, _offset);
if ((_value == 0 || _value==128) && random8(16)==0) { CRGB color = CHSV(beat88(_color_frequency, _offset)>>8, 255, 255);
int8_t sign = _value == 0 ? -1 : +1; _window->setSubPixel(x, 0, &color);
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() { SinesEffect::SinesEffect() {
_sinus = new SinesEffectSinus*[settings.effects.sines.count]; _init();
for (int i=0; i<settings.effects.sines.count; i++) { }
void SinesEffect::_init() {
_count = settings.effects.sines.count;
_sinus = new SinesEffectSinus*[_count];
for (int i=0; i<_count; i++) {
_sinus[i] = new SinesEffectSinus(window); _sinus[i] = new SinesEffectSinus(window);
} }
} }
SinesEffect::~SinesEffect() { SinesEffect::~SinesEffect() {
for (int i=0; i<settings.effects.sines.count; i++) { delete _sinus[i]; } _delete();
}
void SinesEffect::_delete() {
for (int i=0; i<_count; i++) {
delete _sinus[i];
}
delete [] _sinus;
} }
boolean SinesEffect::can_be_shown_with_clock() { boolean SinesEffect::can_be_shown_with_clock() {
@ -40,10 +45,13 @@ boolean SinesEffect::can_be_shown_with_clock() {
} }
void SinesEffect::loop(uint16_t ms) { void SinesEffect::loop(uint16_t ms) {
if (settings.effects.sines.count != _count) {
_delete();
_init();
}
// do stuff // do stuff
if (_step++ % 4) return; // Skip 3 out of 4 steps.
window->shift_down_and_blur(); window->shift_down_and_blur();
for (int i=0; i<settings.effects.sines.count; i++) { for (int i=0; i<_count; i++) {
_sinus[i]->loop(ms); _sinus[i]->loop(ms);
} }
} }