diff --git a/include/effect_twirl.h b/include/effect_twirl.h index af850fe..7e13f9b 100644 --- a/include/effect_twirl.h +++ b/include/effect_twirl.h @@ -7,8 +7,9 @@ class TwirlEffect : public Effect { private: uint8_t angleOffset = 0; - double center_x = 8; - double center_y = 8; + uint8_t _center_offset_angle = 0; + double _real_center_x = LED_WIDTH / 2; + double _real_center_y = LED_HEIGHT / 2; public: void loop(); }; diff --git a/src/effect_twirl.cpp b/src/effect_twirl.cpp index 3b867f4..91dab93 100644 --- a/src/effect_twirl.cpp +++ b/src/effect_twirl.cpp @@ -2,11 +2,16 @@ #include "functions.h" void TwirlEffect::loop() { + double center_x = _real_center_x; // - (cos8(_center_offset_angle)>>6); + double center_y = _real_center_y; // + (sin8(_center_offset_angle)>>6); for (int x=0; xwidth; x++) for (int y=0; yheight; y++) { - uint8_t angle = (x==center_x && y==center_y) ? 0 : atan2(y - center_y, x - center_x) / M_PI * 128 + 128 + angleOffset; - uint8_t brightness = sqrt16((center_x - x) * (center_x - x) + (center_y - y) * (center_y - y)) & 0xFF; - CRGB color(CHSV(angle, (brightness<<5) & 0xFF, 255)); + uint8_t angle = atan2(y - center_y, x - center_x) / M_PI * 128 + 128 + angleOffset; + uint16_t distance = sqrt16((center_x - x) * (center_x - x) + (center_y - y) * (center_y - y)); + if (distance > 255) distance = 255; + angle -= distance << 2; + CRGB color(CHSV(angle, 255, 255 - distance*16)); window->setPixel(x, y, &color); } angleOffset += 1; + if (angleOffset % 17 == 0) _center_offset_angle++; }