pitrix/src/effect_sines.cpp

49 lines
1.2 KiB
C++
Raw Normal View History

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);
}
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() {
for (int i=0; i<EFFECT_SINES_COUNT; i++) {
_sinus[i] = new SinesEffectSinus(window);
}
}
SinesEffect::~SinesEffect() {
for (int i=0; i<EFFECT_SINES_COUNT; i++) { delete _sinus[i]; }
}
boolean SinesEffect::can_be_shown_with_clock() {
return true;
}
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();
for (int i=0; i<EFFECT_SINES_COUNT; i++) {
_sinus[i]->loop(ms);
2019-09-25 04:25:16 +00:00
}
}