diff --git a/include/effect_dvd.h b/include/effect_dvd.h index 39fbbc5..e632700 100644 --- a/include/effect_dvd.h +++ b/include/effect_dvd.h @@ -4,8 +4,8 @@ class DvdEffect : public Effect { private: Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); - uint8_t _x = 0; - uint8_t _y = 0; + saccum78 _x = 0; + saccum78 _y = 0; int8_t _x_dir = 1; int8_t _y_dir = 1; CRGB _color; diff --git a/src/effect_dvd.cpp b/src/effect_dvd.cpp index 5239661..6432034 100644 --- a/src/effect_dvd.cpp +++ b/src/effect_dvd.cpp @@ -3,27 +3,41 @@ void DvdEffect::loop(uint16_t ms) { bool dir_changed = false; - EVERY_N_MILLISECONDS( 250 ) { - _x += _x_dir; - _y += _y_dir; + + _x += _x_dir * settings.effects.dvd.speed; + _y += _y_dir * settings.effects.dvd.speed; - if (_x == 0 || _x + settings.effects.dvd.width >= window->width) { - _x_dir = -_x_dir; - dir_changed = true; - } - if (_y == 0 || _y + settings.effects.dvd.height >= window->height) { - _y_dir = -_y_dir; - dir_changed = true; - } + if (_x <= 0) { + _x = -_x; + _x_dir = -_x_dir; + dir_changed = true; + //LOGln("speed: %d", settings.effects.dvd.speed); + } else if (_x + (settings.effects.dvd.width << 8) >= (window->width << 8)) { + _x -= 2*settings.effects.dvd.speed; + _x_dir = -_x_dir; + dir_changed = true; + } + + if (_y <= 0) { + _y = -_y; + _y_dir = -_y_dir; + dir_changed = true; + } else if (_y + (settings.effects.dvd.height << 8) >= (window->height << 8)) { + _y -= 2*settings.effects.dvd.speed; + _y_dir = -_y_dir; + dir_changed = true; } window->clear(); + + if (dir_changed) _color = (CRGB)CHSV(random8(), 255, 255); for (int x=0; xsetPixel(_x + x, _y + y, (CRGB*)&_color); + window->setSubPixel(_x + (x<<8), _y + (y<<8), (CRGB*)&_color); + } + for (int x=1; xsetPixel((_x>>8) + x, (_y>>8) + y, (CRGB*)&_color); } - - if (dir_changed) _color = (CRGB)CHSV(random8(), 255, 255); } bool DvdEffect::can_be_shown_with_clock() { return true; }