pitrix/src/effect_tv_static.cpp

28 lines
1.0 KiB
C++
Raw Normal View History

#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;
accum88 dark_position = (beat16(settings.effects.tv_static.black_bar_speed) * _window->width) >> 8;
for (uint8_t y=0; y<_window->height; y++) {
accum88 row_dark_position = (dark_position + (y<<8)/3) % (_window->width<<8);
for (uint8_t x=0; x<_window->width; x++) {
uint8_t brightness = random8();
uint8_t darkening = 0;
accum88 distance = (x<<8) - row_dark_position;
if (distance < 256) darkening = random8(distance, 255);
else if (distance < (4<<8)) darkening = random8(distance >> 2, 255);
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;
}