pitrix/src/effect_lightspeed.cpp

64 lines
1.4 KiB
C++

#include "effect_lightspeed.h"
#include "config.h"
#include "functions.h"
#include "prototypes.h"
LightspeedEffect::LightspeedEffect() {
window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
_init();
}
LightspeedEffect::~LightspeedEffect() {
delete window;
_delete();
}
void LightspeedEffect::_init() {
_count = settings.effects.lightspeed.count;
_stars = new LightspeedEffectStar[_count];
for (int i=0; i<_count; i++) {
_stars[i] = LightspeedEffectStar();
}
}
void LightspeedEffect::_delete() {
delete[] _stars;
}
void LightspeedEffect::loop(uint16_t ms) {
if (settings.effects.lightspeed.count != _count) {
_delete();
_init();
}
window->clear();
for (int i=0; i<_count; i++) {
_stars[i].loop(window);
}
}
boolean LightspeedEffect::can_be_shown_with_clock() { return true; };
LightspeedEffectStar::LightspeedEffectStar() {
_init();
}
void LightspeedEffectStar::_init() {
_angle = random16();
_start = 0;
_speed = random16(128, 2<<8);
_target = random16(25<<8, 35<<8);
_saturation = random8(20);
}
void LightspeedEffectStar::loop(Window* win) {
CRGB col = CHSV(192, _saturation, 255);
if (_start < (8<<8)) {
win->lineWithAngle(win->width/2, win->height/2, _angle, 0, _start>>8, &col);
} else {
win->lineWithAngle(win->width/2, win->height/2, _angle, (_start>>8) - 8, 8, &col);
}
_start+=_speed;
//_angle+=8<<8;
if (_start > _target) _init();
}