Moved all individual effects into a subfolder {src,include}/effects/

This commit is contained in:
2020-11-04 06:26:02 +01:00
parent b9cfc6568b
commit 7747e38253
52 changed files with 51 additions and 51 deletions

View File

@ -0,0 +1,9 @@
#pragma once
#include "Effect.h"
class AnalogClockEffect : public Effect {
public:
void loop(uint16_t ms);
String get_name() override { return "analog_clock"; }
};

View File

@ -0,0 +1,24 @@
#pragma once
#include "Effect.h"
#include "prototypes.h"
#include "my_fastled.h"
#include "Animation.h"
class AnimationEffect : public Effect {
private:
Animation *animation;
const char* name;
uint16_t xOffset;
uint16_t yOffset;
unsigned long _last_blink_at;
uint16_t _blink_freq;
public:
AnimationEffect(const char* name, uint32_t bg_color=0x000000, int x=0, int y=0);
static AnimationEffect* Blinker(const char* name, uint16_t interval, uint32_t color, uint32_t background_color=0x000000);
~AnimationEffect();
AnimationEffect* setFgColor(uint32_t c);
AnimationEffect* setBlinkFrequency(uint16_t);
void loop(uint16_t ms);
String get_name() override;
};

15
include/effects/bell.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include "Effect.h"
#include "functions.h"
class BellEffect : public Effect {
private:
CRGB color_on = CRGB(0xFFFF00);
CRGB color_off = CRGB(0x000000);
boolean invert = false;
public:
void loop(uint16_t ms);
String get_name() override { return "bell"; }
};

View File

@ -0,0 +1,21 @@
#pragma once
#include "Effect.h"
class BigClockEffect : public Effect {
protected:
CRGB _color_font = CRGB(0xAAAAAA);
CRGB _color_seconds_light = CRGB(0xFFFF00);
CRGB _color_seconds_dark = CRGB(0xAA0000);
CRGB _color_seconds_moving_light = CRGB(0x666600);
CRGB _color_seconds_moving_dark = CRGB(0x660000);
virtual CRGB _get_color_font() { return CRGB(0xAAAAAA); }
void _draw_seconds(uint8_t seconds);
virtual void _draw_border_pixel(accum88 pos, CRGB* color);
void _draw_colon(bool odd);
public:
virtual void loop(uint16_t ms);
String get_name() override { return "big_clock"; }
};

32
include/effects/blur2d.h Normal file
View File

@ -0,0 +1,32 @@
#pragma once
#include "prototypes.h"
#include "functions.h"
#include "Effect.h"
class Blur2DBlob {
private:
accum88 _x_freq;
accum88 _y_freq;
uint8_t _color_freq;
public:
Blur2DBlob();
void render(Window* win);
};
class Blur2DEffect : public Effect {
private:
Window* window = &Window::window_with_clock;
uint8_t _count;
Blur2DBlob* _blobs;
public:
Blur2DEffect();
~Blur2DEffect();
void _init();
void _delete();
boolean supports_window = true;
boolean can_be_shown_with_clock();
void loop(uint16_t ms);
String get_name() override { return "blur2d"; }
};

18
include/effects/clock.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include "Effect.h"
#include "prototypes.h"
#include "my_fastled.h"
#include "Window.h"
class ClockEffect : public Effect {
protected:
Window* window = &Window::window_clock;
public:
virtual ~ClockEffect();
virtual void loop(uint16_t ms);
String get_name() override { return "clock"; }
void loop_with_invert(bool invert);
void loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t y);
};

23
include/effects/cycle.h Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include "Effect.h"
#include "effects.h"
class CycleEffect : public Effect {
private:
Effect* effect = NULL;
uint16_t effect_id = -1;
unsigned long effectSince = 0;
uint16_t _heap_free = 0;
uint8_t _effects_count;
public:
CycleEffect();
~CycleEffect();
void changeEffect();
boolean can_be_shown_with_clock();
boolean clock_as_mask();
String get_name() override;
void loop(uint16_t ms);
};

11
include/effects/diamond.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include "Effect.h"
class DiamondEffect : public Effect {
private:
Window* window = &Window::window_with_clock;
public:
void loop(uint16_t ms) override;
bool can_be_shown_with_clock() override;
String get_name() override { return "diamond"; }
};

18
include/effects/dvd.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include "Effect.h"
class DvdEffect : public Effect {
private:
Window* window = &Window::window_with_clock;
saccum78 _x = 0;
saccum78 _y = 0;
int8_t _x_dir = 1;
int8_t _y_dir = 1;
CRGB _color;
public:
DvdEffect();
~DvdEffect();
void loop(uint16_t ms) override;
bool can_be_shown_with_clock() override;
String get_name() override { return "dvd"; }
};

35
include/effects/dynamic.h Normal file
View File

@ -0,0 +1,35 @@
#pragma once
#include "Effect.h"
#include "config.h"
class SingleDynamicEffect : public Effect {
protected:
static const int factor = 2;
static const int tile_count = LED_WIDTH/factor * LED_HEIGHT/factor;
CRGB tiles[tile_count];
CRGB old_tiles[tile_count];
uint8_t blend = 0;
public:
SingleDynamicEffect();
void init();
boolean can_be_shown_with_clock();
virtual void loop(uint16_t ms);
void draw();
String get_name() override { return "single_dynamic"; }
};
class MultiDynamicEffect : public SingleDynamicEffect {
public:
void loop(uint16_t ms);
String get_name() override { return "multi_dynamic"; }
};
class BigDynamicEffect : public Effect {
private:
Window* window = &Window::window_with_clock;
public:
void loop(uint16_t ms);
~BigDynamicEffect();
boolean can_be_shown_with_clock() override;
String get_name() override { return "big_dynamic"; }
};

20
include/effects/fire.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include "Effect.h"
#include "my_fastled.h"
class FireEffect : public Effect {
private:
uint8_t* data;
uint8_t spark_temp();
void cooldown();
void spark();
void propagate();
void draw();
static CRGBPalette16 palette;
public:
FireEffect();
~FireEffect();
void loop(uint16_t ms);
String get_name() override { return "fire"; }
};

View File

@ -0,0 +1,57 @@
#pragma once
#include "prototypes.h"
#include "functions.h"
#include "Effect.h"
enum FireworkDotType { FIREWORK_DOT_NONE, FIREWORK_DOT_SHELL, FIREWORK_DOT_SPARK };
class FireworkEffect;
class FireworkEffectDot {
private:
Window* _window;
FireworkEffect* _main;
accum88 _x;
accum88 _y;
saccum78 _xv;
saccum78 _yv;
accum88 _r;
CRGB _color;
void _screenscale(accum88 a, byte n, byte& screen, byte& screenerr);
int16_t _scale15by8_local(int16_t i, fract8 scale);
public:
byte show;
FireworkDotType type;
FireworkEffectDot(Window* w, FireworkEffect* e);
void draw();
void move();
void ground_launch();
void sky_burst(accum88 basex, accum88 basey, saccum78 basedv, CRGB& basecolor);
};
class FireworkEffect : public Effect {
private:
Window* window = &Window::window_with_clock;
bool _skyburst = 0;
accum88 _burst_x;
accum88 _burst_y;
saccum78 _burst_xv;
saccum78 _burst_yv;
CRGB _burst_color;
FireworkEffectDot* _dot;
FireworkEffectDot** _sparks;
public:
FireworkEffect();
~FireworkEffect();
void skyburst(accum88 x, accum88 y, saccum78 xv, saccum78 yv, CRGB c);
boolean supports_window = true;
boolean can_be_shown_with_clock();
void loop(uint16_t ms);
String get_name() override { return "firework"; }
};

23
include/effects/gol.h Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include "Effect.h"
class GolEffect : public Effect {
private:
uint8_t *_data;
uint8_t *_old;
uint8_t _blend;
uint8_t _hue = 0;
uint8_t _old_hue = 0;
uint16_t _step;
void _advance();
void _draw();
void _initialize();
public:
GolEffect();
~GolEffect();
void loop(uint16_t ms);
bool can_be_shown_with_clock();
String get_name() override { return "gol"; }
};

View File

@ -0,0 +1,32 @@
#pragma once
#include "Effect.h"
#include "my_fastled.h"
class LightspeedEffectStar {
private:
uint16_t _angle;
accum88 _distance;
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"; }
};

19
include/effects/marquee.h Normal file
View File

@ -0,0 +1,19 @@
#pragma once
#include "prototypes.h"
#include "functions.h"
#include "Effect.h"
class MarqueeEffect : public Effect {
private:
Window* window = &Window::window_with_clock;
String _text = String("No text set +++ ");
saccum78 _position = (window->width<<8);
public:
boolean supports_window = true;
boolean can_be_shown_with_clock();
void loop(uint16_t ms);
void apply_option(String key, String value) override;
String get_name() override { return "marquee"; }
};

105
include/effects/matrix.h Normal file
View File

@ -0,0 +1,105 @@
#pragma once
#include "prototypes.h"
#include "Effect.h"
#include "config.h"
#include "my_fastled.h"
#include "my_color_palettes.h"
class MatrixEffectColumn {
protected:
Window* window;
saccum78 x, y;
uint8_t length = 1;
uint8_t _direction = 2;
bool _random_direction = false;
virtual CRGB _getColor(uint8_t height);
virtual void restart(bool completely_random);
private:
uint16_t speed;
boolean running;
unsigned long last_move = 0;
public:
static const uint8_t DIR_NORTH = 0;
static const uint8_t DIR_EAST = 1;
static const uint8_t DIR_SOUTH = 2;
static const uint8_t DIR_WEST = 3;
MatrixEffectColumn(Window* win, uint8_t direction=0, bool random_direction=false);
virtual ~MatrixEffectColumn() {};
void advance(uint16_t ms);
void draw();
void loop(uint16_t ms);
};
class RainbowMatrixEffectColumn : public MatrixEffectColumn {
protected:
CRGB _getColor(uint8_t height) override;
public:
RainbowMatrixEffectColumn(Window* win, uint8_t dir, bool rnd=false) : MatrixEffectColumn(win, dir, rnd) {};
};
class RandomMatrixEffectColumn : public MatrixEffectColumn {
protected:
uint8_t _hue = 42;
CRGB _getColor(uint8_t height) override;
void restart(bool completely_random) override;
public:
RandomMatrixEffectColumn(Window* win, uint8_t dir, bool rnd=false) : MatrixEffectColumn(win, dir, rnd) {};
};
class ColumnMatrixEffectColumn : public MatrixEffectColumn {
protected:
uint8_t _hue;
CRGB _getColor(uint8_t height) override;
void restart(bool completely_random) override;
public:
ColumnMatrixEffectColumn(Window* win, uint8_t dir, bool rnd=false) : MatrixEffectColumn(win, dir, rnd) {};
};
class MatrixEffectBase : public Effect {
protected:
MatrixEffectColumn** _columns;
uint8_t _count;
virtual uint8_t _get_count();
virtual void _delete();
void _init();
virtual void _create() = 0;
public:
boolean can_be_shown_with_clock();
virtual ~MatrixEffectBase();
void loop(uint16_t ms);
};
class MatrixEffect : public MatrixEffectBase {
protected:
void _create() override;
public:
MatrixEffect();
String get_name() override { return "matrix"; }
};
class RainbowMatrixEffect : public MatrixEffectBase {
protected:
void _create() override;
public:
RainbowMatrixEffect();
String get_name() override { return "rainbow_matrix"; }
};
class RandomMatrixEffect : public MatrixEffectBase {
protected:
uint8_t _get_count() override;
void _create() override;
public:
RandomMatrixEffect();
String get_name() override { return "random_matrix"; }
};
class ColumnMatrixEffect : public MatrixEffectBase {
protected:
void _create() override;
public:
ColumnMatrixEffect();
String get_name() override { return "column_matrix"; }
};

View File

@ -0,0 +1,16 @@
#pragma once
#include "Effect.h"
#include "my_fastled.h"
class PixelClockEffect : public Effect {
private:
CRGB* _color_seconds;
CRGB* _color_minutes;
public:
PixelClockEffect();
~PixelClockEffect();
void loop(uint16_t ms);
bool can_be_shown_with_clock();
String get_name() override { return "pixel_clock"; }
};

View File

@ -0,0 +1,44 @@
#pragma once
#include "prototypes.h"
#include "functions.h"
#include "Effect.h"
enum SinematrixColorScheme {
SINEMATRIX_COLOR_PASTEL_RAINBOW,
SINEMATRIX_COLOR_RAINBOW,
SINEMATRIX_COLOR_PURPLEFLY,
};
class Sinematrix3Effect : public Effect {
private:
double pangle = 0;
double angle = 0;
double sx = 0;
double sy = 0;
double tx = 0;
double ty = 0;
double cx = 0;
double cy = 0;
double rcx = 0;
double rcy = 0;
double angle2 = 0;
double sx2 = 0;
double sy2 = 0;
double tx2 = 0;
double ty2 = 0;
double basecol = 0;
double fx = 1.0 / (LED_WIDTH / PI);
double fy = 1.0 / (LED_HEIGHT / PI);
Matrix rotate;
SinematrixColorScheme _color_scheme;
CRGB _get_color(int value);
public:
Sinematrix3Effect(SinematrixColorScheme s = SINEMATRIX_COLOR_PASTEL_RAINBOW): _color_scheme(s) {};
boolean supports_window = true;
boolean can_be_shown_with_clock();
boolean clock_as_mask();
void loop(uint16_t ms);
String get_name() override { return "sinematrix3"; }
};

34
include/effects/sines.h Normal file
View File

@ -0,0 +1,34 @@
#pragma once
#include "prototypes.h"
#include "functions.h"
#include "Effect.h"
class SinesEffectSinus {
private:
uint16_t _frequency;
uint16_t _color_frequency;
uint16_t _amplitude;
uint16_t _x;
uint16_t _offset;
Window* _window;
public:
SinesEffectSinus(Window* w);
void loop(uint16_t ms);
};
class SinesEffect : public Effect {
private:
SinesEffectSinus** _sinus;
uint8_t _count;
void _init();
void _delete();
public:
SinesEffect();
~SinesEffect();
boolean supports_window = true;
boolean can_be_shown_with_clock();
void loop(uint16_t ms);
String get_name() override { return "sines"; }
};

68
include/effects/snake.h Normal file
View File

@ -0,0 +1,68 @@
#pragma once
#include "Effect.h"
#include "prototypes.h"
#define SNAKE_DIR_NORTH 0
#define SNAKE_DIR_EAST 1
#define SNAKE_DIR_SOUTH 2
#define SNAKE_DIR_WEST 3
#define SNAKE_DEBUG false
class SnakeEffect : public Effect {
private:
Coords _pos;
Coords _apple;
Coords _tail;
int8_t _dir = SNAKE_DIR_NORTH;
uint8_t* _map;
uint16_t _pixels;
uint8_t _length;
unsigned long _last_apple_at;
unsigned long _last_move_at;
uint16_t _round;
// Neural net config
// These are actually float values. But in order to prevent rounding errors and stuff, they are provided
// in form of the raw binary data of the IEE754 floating point numbers.
// In _decide() there's code to memcpy()-convert them to a float.
// Round 340, 223.4 points, length 39, 36% stopped, 64% died
// const uint32_t _weights[36] = {0xbd8e626e, 0xbee2cd2c, 0x3e4d5cab, 0x3eceb8c3, 0xbed0a514, 0x3ec62438, 0x3e947ed4, 0xbe4b8bf2, 0xbf301113, 0xbf3f0a75, 0x3f1868f7, 0xbf0253ca, 0xbedca2f2, 0xbd547c6d, 0x3edd6a8a, 0xbd4b97b6, 0x3f64ec26, 0xbe5323c1, 0x3eccf87d, 0xbf2d4796, 0xbf62b6e8, 0xbf71daf6, 0xbf03f08e, 0xbf222609, 0x3e26c03c, 0xbf497837, 0xbee4d175, 0x3ec601de, 0x3e4e0695, 0x3eef2619, 0xbe849370, 0xbf18fb2b, 0x3f25bbd1, 0xbf3dcd78, 0x3f37a58d, 0x3ef4a25b};
// Round 630, 221.0 points, length 38, 36% stopped, 64% died
const uint32_t _weights[36] = {0xbd25943f, 0xbf279d81, 0x3e25d128, 0x3ec62438, 0x3f0e719c, 0x3eefbea9, 0x3e947ed4, 0xbe5323c1, 0xbf2d4796, 0xbf3f0a75, 0x3f0e45d9, 0xbf0253ca, 0xbedca2f2, 0xbd79073c, 0x3ede80ec, 0xbd4b97b6, 0x3f69a6be, 0xbe4b8bf2, 0x3eccf87d, 0xbf301113, 0xbf62b6e8, 0xbf71daf6, 0xbf204130, 0xbf222609, 0x3e26c03c, 0xbf497837, 0xbee4d175, 0x3ec601de, 0x3e4954eb, 0x3eef2619, 0xbe849370, 0xbf18fb2b, 0x3f25bbd1, 0xbf3b4e44, 0x3f484d59, 0x3edd6a8a};
// Round 193, 164.8 points, length 36, 6% stopped, 94% died
//const uint32_t _weights[36] = {0x3e872ffb, 0xbea57262, 0xbee269bf, 0x3ed790a3, 0xbf54014f, 0x3ecde0a6, 0xbf240a93, 0xbe9e4782, 0x3f205106, 0xbf4465c2, 0xbf79579a, 0xbf07f122, 0x3ed0e1bc, 0xbf7a5a09, 0xbf0fc70b, 0xbf6d1971, 0xbe0f5585, 0xbec94b12, 0x3f51f7a9, 0x3eaac42b, 0xbe6aafa6, 0x3d3e3ce3, 0xbf7c4232, 0xbe634103, 0x3f800000, 0x3eff886c, 0x3deae1e8, 0x3eea6988, 0xbf800000, 0xbf426a20, 0x3e3a0a45, 0xbe848803, 0x3e84e8c9, 0x3ef9fabc, 0xbe7733e6, 0xbecda633};
// Round 13650, 244.8 points, length 42, 34% stopped, 66% died
//const uint32_t _weights[36] = {0xbeb99de3, 0x3e6ca488, 0xbe3e9dad, 0xbed38d4e, 0x3f279fc1, 0xbd367111, 0xbf473843, 0xbf800000, 0x3f614edc, 0xbecc734f, 0xbe59b29d, 0x3d479078, 0x3efa7ca6, 0xbedc6ce6, 0x3f4626a1, 0x3e9d8c2c, 0x3f29e25c, 0x3ebde05d, 0x3e8f3e29, 0xbe8ad92c, 0xbe148f2d, 0x3d4a3ca7, 0xbf800000, 0x3d9cd634, 0x3f29802e, 0xbf2cc57e, 0xbcbfafff, 0x3e280b8a, 0x3f5ff9a3, 0xbf4e29c9, 0x3e8936d2, 0xbf49dda9, 0xbe9bf4c7, 0x3e203ea8, 0xbd4edf4d, 0xbf4e3c05};
const uint8_t _net_layout[3] = {6, 4, 3};
const uint8_t _net_layers = 3;
const uint8_t _net_total_size = 36;
uint8_t _head_rounds = 0;
uint8_t _tail_rounds = 0;
uint16_t _xy2i(uint8_t x, uint8_t y);
uint16_t _xy2i(Coords c);
Coords _i2xy(uint16_t i);
Coords _new_pos(uint8_t dir);
uint8_t _dying = 0;
bool _is_free(uint8_t dir);
uint8_t _free_spaces(uint8_t dir);
uint8_t _to_apple(uint8_t dir);
void _place_apple();
void _init();
void _decide();
uint8_t _coords_to_field_id(Coords);
int8_t _manual_decision();
void _move();
void _draw();
public:
SnakeEffect();
~SnakeEffect();
void loop(uint16_t ms);
boolean can_be_shown_with_clock();
String get_name() override { return "snake"; }
};

15
include/effects/static.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include "Effect.h"
#include "my_fastled.h"
class StaticEffect : public Effect {
private:
CRGB color;
public:
StaticEffect(CRGB col);
boolean supports_window = true;
void loop(uint16_t ms);
String get_name() override { return "static"; }
};

16
include/effects/timer.h Normal file
View File

@ -0,0 +1,16 @@
#pragma once
#include "Effect.h"
#include "prototypes.h"
#include "my_fastled.h"
#include "Window.h"
class TimerEffect : public Effect {
protected:
Window* window = new Window(0, 0, LED_WIDTH, 6);
public:
~TimerEffect();
void loop(uint16_t ms);
String get_name() override { return "timer"; }
};

View File

@ -0,0 +1,30 @@
#pragma once
#include "Effect.h"
#include "prototypes.h"
#include "my_fastled.h"
#include "Window.h"
#include "config.h"
#include <WiFiUdp.h>
class Tpm2NetEffect : public Effect {
protected:
Window* window = &Window::window_full;
WiFiUDP _udp;
uint16_t _pixel_index = 0;
void _parse_command(uint16_t size, uint8_t packet_number);
void _parse_data(uint16_t size, uint8_t packet_number);
void _respond(uint8_t* data, uint8_t len);
void _respond_ack();
void _respond_with_data(uint8_t* data, uint8_t len);
void _respond_unknown_command();
unsigned long _last_packet_at = 0;
public:
Tpm2NetEffect();
virtual ~Tpm2NetEffect();
virtual void loop(uint16_t ms);
bool can_be_shown_with_clock();
String get_name() override { return "tpm2.net"; }
};

View File

@ -0,0 +1,12 @@
#pragma once
#include "Effect.h"
class TvStaticEffect : public Effect {
private:
Window* _window = &Window::window_with_clock;
public:
~TvStaticEffect();
void loop(uint16_t ms) override;
bool can_be_shown_with_clock() override;
String get_name() override { return "tv_static"; }
};

18
include/effects/twirl.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include "Effect.h"
#include <Arduino.h>
class TwirlEffect : public Effect {
private:
uint8_t angleOffset = 0;
uint8_t _center_offset_angle = 0;
double _real_center_x = LED_WIDTH / 2;
double _real_center_y = LED_HEIGHT / 2;
public:
void loop(uint16_t ms);
boolean can_be_shown_with_clock() override;
boolean clock_as_mask() override;
String get_name() override { return "twirl"; }
};