effect_lightspeed: Speed changes.

This commit is contained in:
Fabian Schlenz 2019-11-03 13:56:07 +01:00
parent 994f4894dd
commit 439e2de17f
3 changed files with 15 additions and 7 deletions

View File

@ -6,7 +6,7 @@
class LightspeedEffectStar { class LightspeedEffectStar {
private: private:
uint16_t _angle; uint16_t _angle;
accum88 _start; accum88 _distance;
uint16_t _speed; uint16_t _speed;
uint16_t _target; uint16_t _target;
uint8_t _saturation; uint8_t _saturation;

View File

@ -217,6 +217,11 @@ void Window::lineWithAngle(uint8_t x, uint8_t y, uint16_t angle, uint8_t startdi
x1 = (x<<8) + (startdist<<8) * cos16(angle) / 0x10000; x1 = (x<<8) + (startdist<<8) * cos16(angle) / 0x10000;
y1 = (y<<8) + (startdist<<8) * sin16(angle) / 0x10000; y1 = (y<<8) + (startdist<<8) * sin16(angle) / 0x10000;
} }
if (length==0) {
setSubPixel(x1, y1, color);
return;
}
saccum78 x2 = (x<<8) + ((startdist + length)<<8) * cos16(angle) / 0x10000; saccum78 x2 = (x<<8) + ((startdist + length)<<8) * cos16(angle) / 0x10000;
saccum78 y2 = (y<<8) + ((startdist + length)<<8) * sin16(angle) / 0x10000; saccum78 y2 = (y<<8) + ((startdist + length)<<8) * sin16(angle) / 0x10000;

View File

@ -40,11 +40,12 @@ boolean LightspeedEffect::can_be_shown_with_clock() { return true; };
LightspeedEffectStar::LightspeedEffectStar() { LightspeedEffectStar::LightspeedEffectStar() {
_init(); _init();
_distance = random16(10<<8);
} }
void LightspeedEffectStar::_init() { void LightspeedEffectStar::_init() {
_angle = random16(); _angle = random16();
_start = 0; _distance = 0;
_speed = random16(128, 2<<8); _speed = random16(128, 2<<8);
_target = random16(25<<8, 35<<8); _target = random16(25<<8, 35<<8);
_saturation = random8(20); _saturation = random8(20);
@ -52,12 +53,14 @@ void LightspeedEffectStar::_init() {
void LightspeedEffectStar::loop(Window* win) { void LightspeedEffectStar::loop(Window* win) {
CRGB col = CHSV(192, _saturation, 255); CRGB col = CHSV(192, _saturation, 255);
if (_start < (8<<8)) { accum88 current_speed = _speed * beatsin16(0x100, 0, 65535) / 65535;
win->lineWithAngle(win->width/2, win->height/2, _angle, 0, _start>>8, &col); uint8_t length = (current_speed>>6);
if (_distance < (length<<8)) {
win->lineWithAngle(win->width/2, win->height/2, _angle, 0, _distance>>8, &col);
} else { } else {
win->lineWithAngle(win->width/2, win->height/2, _angle, (_start>>8) - 8, 8, &col); win->lineWithAngle(win->width/2, win->height/2, _angle, (_distance>>8) - length, length, &col);
} }
_start+=_speed; _distance += current_speed;
//_angle+=8<<8; //_angle+=8<<8;
if (_start > _target) _init(); if (_distance > _target) _init();
} }