pitrix/src/effect_lightspeed.cpp

66 lines
1.5 KiB
C++

#include "effect_lightspeed.h"
#include "config.h"
#include "functions.h"
#include "prototypes.h"
LightspeedEffect::LightspeedEffect() {
window = &Window::window_with_clock;
_init();
}
LightspeedEffect::~LightspeedEffect() {
_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();
_distance = random16(10<<8);
}
void LightspeedEffectStar::_init() {
_angle = random16();
_distance = 0;
_speed = random16(128, 2<<8);
_target = random16(25<<8, 35<<8);
_saturation = random8(100);
}
void LightspeedEffectStar::loop(Window* win) {
CRGB col = CHSV(192, _saturation, 255);
accum88 current_speed = _speed * beatsin16(0x100, 0, 65535) / 65535;
uint8_t length = (current_speed>>6);
if (_distance < (length<<8)) {
win->lineWithAngle(win->width/2, win->height/2, _angle, 0, _distance>>8, &col);
} else {
win->lineWithAngle(win->width/2, win->height/2, _angle, (_distance>>8) - length, length, &col);
}
_distance += current_speed;
//_angle+=8<<8;
if (_distance > _target) _init();
}