Added new effect type SimpleEffect for, well, simple effects. Added new effect slow_blinking based on this and also converted the confetti effects.

This commit is contained in:
Fabian Schlenz 2020-11-04 05:58:00 +01:00
parent a96f6c79e3
commit f9e6a5ebd6
6 changed files with 54 additions and 46 deletions

23
include/SimpleEffect.h Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include "Effect.h"
#include "prototypes.h"
class SimpleEffect : public Effect {
protected:
Window* window = &Window::window_full; // Use a full screen window per default.
boolean _fade_out = false;
boolean _random_colors = false;
boolean _cycle_color = true;
uint8_t _color = 0;
String _name;
simple_effect_t _method;
public:
SimpleEffect(String name, simple_effect_t method): _name { name }, _method { method } {};
SimpleEffect* with_fadeout() { _fade_out=true; return this;}
SimpleEffect* with_random_colors() { _random_colors=true; return this;}
SimpleEffect* with_static_color(uint8_t color) { _cycle_color=false; _color=color; return this; }
void loop(uint16_t ms) override;
String get_name() { return _name; };
boolean can_be_shown_with_clock() { return true; }
};

View File

@ -1,20 +0,0 @@
#pragma once
#include "Effect.h"
#include "my_fastled.h"
class ConfettiEffect : public Effect {
protected:
virtual CRGB _getColor();
public:
void loop(uint16_t ms);
boolean can_be_shown_with_clock();
String get_name() override { return "confetti"; }
};
class RandomConfettiEffect : public ConfettiEffect {
protected:
CRGB _getColor() override;
String get_name() override { return "random_confetti"; }
};

View File

@ -1,6 +1,7 @@
#pragma once
#include <Arduino.h>
#include "my_fastled.h"
extern uint8_t baseHue;
extern char hostname[30];
@ -31,3 +32,5 @@ typedef struct {
uint16_t x;
uint16_t y;
} Coords;
typedef std::function<int8_t(accum88, uint16_t, uint8_t, uint8_t)> simple_effect_t;

23
src/SimpleEffect.cpp Normal file
View File

@ -0,0 +1,23 @@
#include "SimpleEffect.h"
void SimpleEffect::loop(uint16_t ms) {
if (_fade_out) window->fadeToBlackBy(3);
accum88 t = millis() * 0x100 / 1000;
for(uint8_t x=0; x<window->width; x++) for(uint8_t y=0; y<window->height; y++) {
uint16_t i = y*window->width + x;
int8_t r = _method(t, i, x, y);
if (_fade_out && r==0) {
continue;
}
CRGB color;
if (_random_colors) {
color = CHSV(random8(), 255, abs(r)*2);
} else {
color = CHSV(_cycle_color ? baseHue : _color, r<0?0:255, abs(r)*2);
}
window->setPixel(x, y, &color);
}
}

View File

@ -1,22 +0,0 @@
#include "effect_confetti.h"
#include "config.h"
#include "functions.h"
#include "prototypes.h"
void ConfettiEffect::loop(uint16_t ms) {
window->fadeToBlackBy(3);
for (int i=0; i<settings.effects.confetti.pixels_per_loop; i++) {
CRGB color = _getColor();
window->addPixelColor(random16(LED_COUNT), &color);
}
}
CRGB ConfettiEffect::_getColor() {
return CHSV(baseHue + random8(64), 255, 255);
}
CRGB RandomConfettiEffect::_getColor() {
return CHSV(random8(), 255, 255);
}
boolean ConfettiEffect::can_be_shown_with_clock() { return true; };

View File

@ -11,7 +11,6 @@
#include "effect_matrix.h"
#include "effect_twirl.h"
#include "effect_cycle.h"
#include "effect_confetti.h"
#include "effect_snake.h"
#include "effect_fire.h"
#include "effect_firework.h"
@ -26,6 +25,7 @@
#include "effect_lightspeed.h"
#include "effect_diamond.h"
#include "effect_tpm2_net.h"
#include "SimpleEffect.h"
Effect* current_effect;
@ -47,8 +47,8 @@ EffectEntry effects[] = {
/* 10 */ {"rainbow_matrix", true, [](){ return new RainbowMatrixEffect(); }},
/* 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(); }},
/* 13 */ {"confetti", true, [](){ return (new SimpleEffect("confetti", [](accum88 t, uint16_t i, uint8_t x, uint8_t y)->int8_t{return random8()>252 ? 127 : 0;}))->with_fadeout();}},
/* 14 */ {"rainbow_confetti", true, [](){ return (new SimpleEffect("rainbow_confetti", [](accum88 t, uint16_t i, uint8_t x, uint8_t y)->int8_t{return random8()>252 ? 127 : 0;}))->with_fadeout()->with_random_colors();}},
/* 15 */ {"snake", true, [](){ return new SnakeEffect(); }},
/* 16 */ {"firework", true, [](){ return new FireworkEffect(); }},
/* 17 */ {"gol", true, [](){ return new GolEffect(); }},
@ -68,8 +68,9 @@ EffectEntry effects[] = {
/* 31 */ {"child", 0, [](){ return AnimationEffect::Blinker("/child.pia", 300, 0xFFFF00); }},
/* 32 */ {"diamond", true, [](){ return new DiamondEffect(); }},
/* 33 */ {"tpm2.net", 0, [](){ return new Tpm2NetEffect(); }},
/* 34 */ {"slow_blinking", true, [](){ return new SimpleEffect("slow_blinking", [](accum88 t, uint16_t i, uint8_t x, uint8_t y)->int8_t{return sin8((t>>3) + ((((x+1)*(y+1)*i*15) >> 2) & 0xFF))-128;});}},
};
const uint8_t effects_size = 34;
const uint8_t effects_size = 35;
Effect* select_effect(const char* name) {