28 lines
1004 B
C++
28 lines
1004 B
C++
|
#include "effect_tv_static.h"
|
||
|
|
||
|
void TvStaticEffect::loop(uint16_t ms) {
|
||
|
uint8_t dark_position = (millis() % settings.effects.tv_static.black_bar_speed) * _window->width / settings.effects.tv_static.black_bar_speed;
|
||
|
for (uint8_t y=0; y<_window->height; y++) {
|
||
|
uint8_t row_dark_position = (dark_position + y/3) % _window->width;
|
||
|
for (uint8_t x=0; x<_window->width; x++) {
|
||
|
uint8_t brightness = random8();
|
||
|
uint8_t darkening = 0;
|
||
|
uint8_t distance = x - row_dark_position;
|
||
|
if (distance == 0) darkening = random8(192, 255);
|
||
|
else if (distance == 1) darkening = random8(128, 255);
|
||
|
else if (distance == 2) darkening = random8(92, 192);
|
||
|
else if (distance == 3) darkening = random8(32, 128);
|
||
|
if (darkening > brightness) brightness = 0;
|
||
|
else brightness -= darkening;
|
||
|
CRGB color(brightness, brightness, brightness);
|
||
|
_window->setPixel(x, y, &color);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool TvStaticEffect::can_be_shown_with_clock() { return true; }
|
||
|
|
||
|
TvStaticEffect::~TvStaticEffect() {
|
||
|
delete _window;
|
||
|
}
|