diff --git a/include/effect_lightspeed.h b/include/effect_lightspeed.h index 3e26ed2..ff9e901 100644 --- a/include/effect_lightspeed.h +++ b/include/effect_lightspeed.h @@ -6,7 +6,7 @@ class LightspeedEffectStar { private: uint16_t _angle; - accum88 _start; + accum88 _distance; uint16_t _speed; uint16_t _target; uint8_t _saturation; diff --git a/src/Window.cpp b/src/Window.cpp index b3a5d44..2025076 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -217,6 +217,11 @@ void Window::lineWithAngle(uint8_t x, uint8_t y, uint16_t angle, uint8_t startdi x1 = (x<<8) + (startdist<<8) * cos16(angle) / 0x10000; y1 = (y<<8) + (startdist<<8) * sin16(angle) / 0x10000; } + + if (length==0) { + setSubPixel(x1, y1, color); + return; + } saccum78 x2 = (x<<8) + ((startdist + length)<<8) * cos16(angle) / 0x10000; saccum78 y2 = (y<<8) + ((startdist + length)<<8) * sin16(angle) / 0x10000; diff --git a/src/effect_lightspeed.cpp b/src/effect_lightspeed.cpp index 2bdbe84..0b1883d 100644 --- a/src/effect_lightspeed.cpp +++ b/src/effect_lightspeed.cpp @@ -40,11 +40,12 @@ boolean LightspeedEffect::can_be_shown_with_clock() { return true; }; LightspeedEffectStar::LightspeedEffectStar() { _init(); + _distance = random16(10<<8); } void LightspeedEffectStar::_init() { _angle = random16(); - _start = 0; + _distance = 0; _speed = random16(128, 2<<8); _target = random16(25<<8, 35<<8); _saturation = random8(20); @@ -52,12 +53,14 @@ void LightspeedEffectStar::_init() { void LightspeedEffectStar::loop(Window* win) { CRGB col = CHSV(192, _saturation, 255); - if (_start < (8<<8)) { - win->lineWithAngle(win->width/2, win->height/2, _angle, 0, _start>>8, &col); + accum88 current_speed = _speed * beatsin16(0x100, 0, 65535) / 65535; + uint8_t length = (current_speed>>6); + if (_distance < (length<<8)) { + win->lineWithAngle(win->width/2, win->height/2, _angle, 0, _distance>>8, &col); } else { - win->lineWithAngle(win->width/2, win->height/2, _angle, (_start>>8) - 8, 8, &col); + win->lineWithAngle(win->width/2, win->height/2, _angle, (_distance>>8) - length, length, &col); } - _start+=_speed; + _distance += current_speed; //_angle+=8<<8; - if (_start > _target) _init(); + if (_distance > _target) _init(); }