pitrix/src/effect_dvd.cpp

38 lines
774 B
C++
Raw Normal View History

2019-06-19 20:17:39 +00:00
#include "effect_dvd.h"
#include "my_fastled.h"
void DvdEffect::loop() {
bool dir_changed = false;
EVERY_N_MILLISECONDS( 250 ) {
_x += _x_dir;
_y += _y_dir;
if (_x == 0 || _x + EFFECT_DVD_WIDTH >= window->width) {
_x_dir = -_x_dir;
dir_changed = true;
}
if (_y == 0 || _y + EFFECT_DVD_HEIGHT >= window->height) {
_y_dir = -_y_dir;
dir_changed = true;
}
}
window->clear();
for (int x=0; x<EFFECT_DVD_WIDTH; x++) for (int y=0; y<EFFECT_DVD_HEIGHT; y++) {
window->setPixel(_x + x, _y + y, (CRGB*)&_color);
}
if (dir_changed) _color = (CRGB)CHSV(random8(), 255, 255);
}
bool DvdEffect::can_be_shown_with_clock() { return true; }
DvdEffect::DvdEffect() {
_color = CHSV(random8(), 255, 255);
}
DvdEffect::~DvdEffect() {
delete window;
}