Better and more SimpleEffects.
* Calculations are done using doubles for much easier code. * Binary flags instead of boolean variables for configuration. * New effects sineline, barbershop and zigzag.
This commit is contained in:
@ -1,21 +1,30 @@
|
||||
#pragma once
|
||||
#include "Effect.h"
|
||||
#include "prototypes.h"
|
||||
#include <cmath>
|
||||
|
||||
#define SE_CYCLE_COLORS 1 // Slowly cycle through the rainbow.
|
||||
#define SE_RANDOM_PIXEL_COLORS 2 // Every pixel gets a random color every frame.
|
||||
#define SE_ONLY_POSITIVE 4 // Only use colors, not white. This is equivalent to running your output through abs()
|
||||
#define SE_FADEOUT 8 // Fades the old image out. Returning 0 doesn't change the pixel's value.
|
||||
#define SE_RANDOM_STATIC_COLOR 16 // Sets a random static color at start of the effect.
|
||||
#define SE_DEBUG 32 // Prints debug messages.
|
||||
|
||||
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;
|
||||
uint16_t _flags;
|
||||
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; }
|
||||
SimpleEffect(String name, uint16_t flags, simple_effect_t method): _name { name }, _method { method } {
|
||||
_flags = flags;
|
||||
if (_flags & SE_RANDOM_STATIC_COLOR) {
|
||||
_color = random8();
|
||||
_flags &= ~SE_CYCLE_COLORS & ~SE_RANDOM_PIXEL_COLORS;
|
||||
}
|
||||
};
|
||||
void loop(uint16_t ms) override;
|
||||
String get_name() { return _name; };
|
||||
boolean can_be_shown_with_clock() { return true; }
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "effects/clock.h"
|
||||
#include "effects/timer.h"
|
||||
|
||||
#define SIMPLE_EFFECT [](accum88 t, uint16_t i, uint8_t x, uint8_t y)->int8_t
|
||||
#define SIMPLE_EFFECT(name, use_in_cycle, flags, ...) {name, use_in_cycle, [](){ return new SimpleEffect(name, flags, [](double t, uint16_t i, uint8_t x, uint8_t y)->double __VA_ARGS__ ); }}
|
||||
|
||||
struct EffectEntry {
|
||||
const char* name;
|
||||
|
@ -33,4 +33,4 @@ typedef struct {
|
||||
uint16_t y;
|
||||
} Coords;
|
||||
|
||||
typedef std::function<int8_t(accum88, uint16_t, uint8_t, uint8_t)> simple_effect_t;
|
||||
typedef std::function<double(double, uint16_t, uint8_t, uint8_t)> simple_effect_t;
|
Reference in New Issue
Block a user