2019-09-25 04:25:16 +00:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2019-10-01 04:29:32 +00:00
|
|
|
void SinesEffectSinus::loop(uint16_t ms) {
|
2019-09-25 04:25:16 +00:00
|
|
|
_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() {
|
2019-10-02 04:13:55 +00:00
|
|
|
_sinus = new SinesEffectSinus*[settings.effects.sines.count];
|
|
|
|
for (int i=0; i<settings.effects.sines.count; i++) {
|
2019-09-25 04:25:16 +00:00
|
|
|
_sinus[i] = new SinesEffectSinus(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SinesEffect::~SinesEffect() {
|
2019-10-02 04:13:55 +00:00
|
|
|
for (int i=0; i<settings.effects.sines.count; i++) { delete _sinus[i]; }
|
2019-09-25 04:25:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean SinesEffect::can_be_shown_with_clock() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-01 04:29:32 +00:00
|
|
|
void SinesEffect::loop(uint16_t ms) {
|
2019-09-25 04:25:16 +00:00
|
|
|
// do stuff
|
|
|
|
if (_step++ % 4) return; // Skip 3 out of 4 steps.
|
|
|
|
window->shift_down_and_blur();
|
2019-10-02 04:13:55 +00:00
|
|
|
for (int i=0; i<settings.effects.sines.count; i++) {
|
2019-10-01 04:29:32 +00:00
|
|
|
_sinus[i]->loop(ms);
|
2019-09-25 04:25:16 +00:00
|
|
|
}
|
|
|
|
}
|