2019-05-29 22:49:54 +00:00
|
|
|
#include "effect_twirl.h"
|
|
|
|
#include "functions.h"
|
|
|
|
|
|
|
|
void TwirlEffect::loop() {
|
2019-09-04 04:01:08 +00:00
|
|
|
double center_x = _real_center_x; // - (cos8(_center_offset_angle)>>6);
|
|
|
|
double center_y = _real_center_y; // + (sin8(_center_offset_angle)>>6);
|
2019-06-11 17:48:09 +00:00
|
|
|
for (int x=0; x<window->width; x++) for (int y=0; y<window->height; y++) {
|
2019-09-04 04:01:08 +00:00
|
|
|
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));
|
2019-06-11 17:48:09 +00:00
|
|
|
window->setPixel(x, y, &color);
|
2019-06-07 04:24:16 +00:00
|
|
|
}
|
|
|
|
angleOffset += 1;
|
2019-09-04 04:01:08 +00:00
|
|
|
if (angleOffset % 17 == 0) _center_offset_angle++;
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|