2019-09-25 04:25:16 +00:00
|
|
|
#include "effect_sines.h"
|
|
|
|
|
|
|
|
SinesEffectSinus::SinesEffectSinus(Window* w) {
|
|
|
|
_window = w;
|
2019-10-04 10:05:54 +00:00
|
|
|
_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();
|
2019-09-25 04:25:16 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 04:29:32 +00:00
|
|
|
void SinesEffectSinus::loop(uint16_t ms) {
|
2019-10-04 10:05:54 +00:00
|
|
|
accum88 x = beatsin88(_frequency, _x-_amplitude, _x+_amplitude, _offset);
|
|
|
|
CRGB color = CHSV(beat88(_color_frequency, _offset)>>8, 255, 255);
|
|
|
|
_window->setSubPixel(x, 0, &color);
|
2019-09-25 04:25:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SinesEffect::SinesEffect() {
|
2019-10-04 10:05:54 +00:00
|
|
|
_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SinesEffect::_init() {
|
|
|
|
_count = settings.effects.sines.count;
|
|
|
|
_sinus = new SinesEffectSinus*[_count];
|
|
|
|
for (int i=0; i<_count; i++) {
|
2019-09-25 04:25:16 +00:00
|
|
|
_sinus[i] = new SinesEffectSinus(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SinesEffect::~SinesEffect() {
|
2019-10-04 10:05:54 +00:00
|
|
|
_delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SinesEffect::_delete() {
|
|
|
|
for (int i=0; i<_count; i++) {
|
|
|
|
delete _sinus[i];
|
|
|
|
}
|
|
|
|
delete [] _sinus;
|
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-10-04 10:05:54 +00:00
|
|
|
if (settings.effects.sines.count != _count) {
|
|
|
|
_delete();
|
|
|
|
_init();
|
|
|
|
}
|
2019-09-25 04:25:16 +00:00
|
|
|
// do stuff
|
|
|
|
window->shift_down_and_blur();
|
2019-10-04 10:05:54 +00:00
|
|
|
for (int i=0; i<_count; i++) {
|
2019-10-01 04:29:32 +00:00
|
|
|
_sinus[i]->loop(ms);
|
2019-09-25 04:25:16 +00:00
|
|
|
}
|
|
|
|
}
|