Made twirl effect a lot more beautiful.

This commit is contained in:
Fabian Schlenz 2019-09-04 06:01:08 +02:00
parent a6cd94e416
commit a05931d7f9
2 changed files with 11 additions and 5 deletions

View File

@ -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();
};

View File

@ -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; x<window->width; x++) for (int y=0; y<window->height; 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++;
}