effect_lightspeed: New effect.
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
Fabian Schlenz 2019-10-24 06:33:16 +02:00
parent b5343b59e5
commit 994f4894dd
5 changed files with 134 additions and 31 deletions

View File

@ -0,0 +1,32 @@
#pragma once
#include "Effect.h"
#include "my_fastled.h"
class LightspeedEffectStar {
private:
uint16_t _angle;
accum88 _start;
uint16_t _speed;
uint16_t _target;
uint8_t _saturation;
void _init();
public:
LightspeedEffectStar();
void loop(Window* win);
};
class LightspeedEffect : public Effect {
private:
LightspeedEffectStar* _stars;
uint8_t _count;
void _init();
void _delete();
public:
LightspeedEffect();
~LightspeedEffect();
void loop(uint16_t ms);
boolean can_be_shown_with_clock();
String get_name() override { return "lightspeed"; }
};

View File

@ -75,6 +75,10 @@ struct Settings {
uint16_t restart_after_steps = 100;
} gol;
struct /* lightspeed */ {
uint16_t count = 25;
} lightspeed;
struct /* sines */ {
uint16_t count = 5;
} sines;

63
src/effect_lightspeed.cpp Normal file
View File

@ -0,0 +1,63 @@
#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();
}

View File

@ -23,43 +23,45 @@
#include "effect_marquee.h"
#include "effect_blur2d.h"
#include "effect_tv_static.h"
#include "effect_lightspeed.h"
Effect* current_effect;
ClockEffect effect_clock;
// We're using 0 instead of false to get a better visual difference between true and false.
const EffectEntry effects[] = {
/* 0 */ {"sinematrix3", true, [](){ return new Sinematrix3Effect(); }},
/* 1 */ {"big_clock", true, [](){ return new BigClockEffect(); }},
/* 2 */ {"clock", false, [](){ return new ClockEffect(); }},
/* 3 */ {"bell", false, [](){ return new BellEffect(); }},
/* 4 */ {"off", false, [](){ return new StaticEffect(0x000000); }},
/* 2 */ {"clock", 0, [](){ return new ClockEffect(); }},
/* 3 */ {"bell", 0, [](){ return new BellEffect(); }},
/* 4 */ {"off", 0, [](){ return new StaticEffect(0x000000); }},
/* 5 */ {"single_dynamic", true, [](){ return new SingleDynamicEffect(); }},
/* 6 */ {"multi_dynamic", true, [](){ return new MultiDynamicEffect(); }},
/* 7 */ {"big_dynamic", true, [](){ return new BigDynamicEffect(); }},
/* 8 */ {"matrix", true, [](){ return new MatrixEffect(); }},
/* 9 */ {"random_matrix", true, [](){ return new RandomMatrixEffect(); }},
/* 10 */ {"rainbow_matrix", true, [](){ return new RainbowMatrixEffect(); }},
/* 11 */ {"cycle", false, [](){ return new CycleEffect(); }},
/* 11 */ {"cycle", 0, [](){ return new CycleEffect(); }},
/* 12 */ {"twirl", true, [](){ return new TwirlEffect(); }},
/* 13 */ {"confetti", true, [](){ return new ConfettiEffect(); }},
/* 14 */ {"random_confetti", true, [](){ return new RandomConfettiEffect(); }},
/* 15 */ {"snake", true, [](){ return new SnakeEffect(); }},
/* 16 */ {"firework", true, [](){ return new FireworkEffect(); }},
/* 17 */ {"gol", true, [](){ return new GolEffect(); }},
/* 18 */ {"pixel_clock", false, [](){ return new PixelClockEffect(); }},
/* 19 */ {"dvd", false, [](){ return new DvdEffect(); }},
/* 20 */ {"analog_clock", false, [](){ return new AnalogClockEffect(); }},
/* 18 */ {"pixel_clock", 0, [](){ return new PixelClockEffect(); }},
/* 19 */ {"dvd", 0, [](){ return new DvdEffect(); }},
/* 20 */ {"analog_clock", 0, [](){ return new AnalogClockEffect(); }},
/* 21 */ {"sines", true, [](){ return new SinesEffect(); }},
/* 22 */ {"blur2d", true, [](){ return new Blur2DEffect(); }},
/* 23 */ {"marquee", 0, [](){ return new MarqueeEffect(); }},
/* 24 */ {"night_clock", false, [](){ return new NightClockEffect(); }},
/* 25 */ {"tv_static", false, [](){ return new TvStaticEffect(); }},
/* 24 */ {"night_clock", 0, [](){ return new NightClockEffect(); }},
/* 25 */ {"tv_static", 0, [](){ return new TvStaticEffect(); }},
/* 26 */ {"sinematrix3_rainbow", true, [](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_RAINBOW); }},
/* 27 */ {"sinematrix3_purplefly", true, [](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_PURPLEFLY); }},
/* 28 */ {"lightspeed", true, [](){ return new LightspeedEffect(); }},
};
const uint8_t effects_size = 28;
const uint8_t effects_size = 29;
Effect* select_effect(const char* name) {

View File

@ -37,6 +37,8 @@ Setting all_settings[] = {
{"effects.gol.blend_speed", &settings.effects.gol.blend_speed, TYPE_UINT8},
{"effects.gol.restart_after_steps", &settings.effects.gol.restart_after_steps, TYPE_UINT8},
{"effects.lightspeed.count", &settings.effects.lightspeed.count, TYPE_UINT8},
{"effects.matrix.length_min", &settings.effects.matrix.length_min, TYPE_UINT8},
{"effects.matrix.length_max", &settings.effects.matrix.length_max, TYPE_UINT8},
{"effects.matrix.speed_min", &settings.effects.matrix.speed_min, TYPE_UINT8},
@ -51,7 +53,7 @@ Setting all_settings[] = {
{"effects.tv_static.black_bar_speed", &settings.effects.tv_static.black_bar_speed, TYPE_UINT16},
};
const uint8_t all_settings_size = 31;
const uint8_t all_settings_size = 32;
bool change_setting(const char* key, uint16_t new_value) {
LOGln("Settings * Setting %s to new value %d.", key, new_value);