sines effect now uses subpixel rendering.
This commit is contained in:
parent
2b7033b685
commit
af1314632e
@ -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();
|
||||
|
@ -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; i<settings.effects.sines.count; i++) {
|
||||
_init();
|
||||
}
|
||||
|
||||
void SinesEffect::_init() {
|
||||
_count = settings.effects.sines.count;
|
||||
_sinus = new SinesEffectSinus*[_count];
|
||||
for (int i=0; i<_count; i++) {
|
||||
_sinus[i] = new SinesEffectSinus(window);
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
@ -40,10 +45,13 @@ boolean SinesEffect::can_be_shown_with_clock() {
|
||||
}
|
||||
|
||||
void SinesEffect::loop(uint16_t ms) {
|
||||
if (settings.effects.sines.count != _count) {
|
||||
_delete();
|
||||
_init();
|
||||
}
|
||||
// do stuff
|
||||
if (_step++ % 4) return; // Skip 3 out of 4 steps.
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user