35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
#include "SimpleEffect.h"
|
|
|
|
void SimpleEffect::loop(uint16_t ms) {
|
|
if (_flags & SE_FADEOUT) window->fadeToBlackBy(3);
|
|
double t = 0.001 * millis();
|
|
for(uint8_t x=0; x<window->width; x++) for(uint8_t y=0; y<window->height; y++) {
|
|
uint16_t i = y*window->width + x;
|
|
double r = _method(t, i, x, y);
|
|
//if (i==0) Serial.printf("t=%f i=%d x=%d y=%d => r=%f, abs(r)=%d\n", t, i, x, y, r, abs(r)*255);
|
|
if ((_flags & SE_DEBUG) && i==17) Serial.printf("t=%f i=%d x=%d y=%d => r=%f, abs(r*255)=%d\n", t, i, x, y, r, (int)abs(r*255));
|
|
if ((_flags & SE_FADEOUT) && r==0) {
|
|
continue;
|
|
}
|
|
|
|
// Clamp r between -1.0 and +1.0
|
|
if (r<-1.0) {
|
|
r = -1.0;
|
|
} else if (r>1.0) {
|
|
r = 1.0;
|
|
}
|
|
|
|
if (_flags & SE_ONLY_POSITIVE) {
|
|
r = abs(r);
|
|
}
|
|
|
|
CRGB color;
|
|
if (_flags & SE_RANDOM_PIXEL_COLORS) {
|
|
color = CHSV(random8(), 255, abs(r*255));
|
|
} else {
|
|
color = CHSV(_flags & SE_CYCLE_COLORS ? baseHue : _color, r<0?0:255, abs(r*255));
|
|
}
|
|
|
|
window->setPixel(x, y, &color);
|
|
}
|
|
} |