Made twirl effect a lot more beautiful.
This commit is contained in:
parent
a6cd94e416
commit
a05931d7f9
@ -7,8 +7,9 @@
|
|||||||
class TwirlEffect : public Effect {
|
class TwirlEffect : public Effect {
|
||||||
private:
|
private:
|
||||||
uint8_t angleOffset = 0;
|
uint8_t angleOffset = 0;
|
||||||
double center_x = 8;
|
uint8_t _center_offset_angle = 0;
|
||||||
double center_y = 8;
|
double _real_center_x = LED_WIDTH / 2;
|
||||||
|
double _real_center_y = LED_HEIGHT / 2;
|
||||||
public:
|
public:
|
||||||
void loop();
|
void loop();
|
||||||
};
|
};
|
||||||
|
@ -2,11 +2,16 @@
|
|||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
|
|
||||||
void TwirlEffect::loop() {
|
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++) {
|
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 angle = 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;
|
uint16_t distance = sqrt16((center_x - x) * (center_x - x) + (center_y - y) * (center_y - y));
|
||||||
CRGB color(CHSV(angle, (brightness<<5) & 0xFF, 255));
|
if (distance > 255) distance = 255;
|
||||||
|
angle -= distance << 2;
|
||||||
|
CRGB color(CHSV(angle, 255, 255 - distance*16));
|
||||||
window->setPixel(x, y, &color);
|
window->setPixel(x, y, &color);
|
||||||
}
|
}
|
||||||
angleOffset += 1;
|
angleOffset += 1;
|
||||||
|
if (angleOffset % 17 == 0) _center_offset_angle++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user