effect_blur2d: Number of blobs is configurable.
This commit is contained in:
parent
aa72196a07
commit
3c0e4af325
@ -4,11 +4,26 @@
|
||||
#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 = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6);
|
||||
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);
|
||||
|
@ -35,6 +35,10 @@ struct Settings {
|
||||
struct /* big_clock */ {
|
||||
uint16_t spacing = 5;
|
||||
} big_clock;
|
||||
|
||||
struct /* blur2d */ {
|
||||
uint16_t count = 5;
|
||||
} blur2d;
|
||||
|
||||
struct /* confetti */ {
|
||||
uint16_t pixels_per_loop = 2;
|
||||
|
@ -1,31 +1,49 @@
|
||||
#include "effect_blur2d.h"
|
||||
Blur2DBlob::Blur2DBlob() {
|
||||
_x_freq = random16(6<<8, 15<<8);
|
||||
_y_freq = random16(6<<8, 15<<8);
|
||||
_color_freq = random8(25, 80);
|
||||
}
|
||||
|
||||
void Blur2DBlob::render(Window* window) {
|
||||
uint8_t x = beatsin16(_x_freq, 0, window->width-1);
|
||||
uint8_t y = beatsin16(_y_freq, 0, window->height-1);
|
||||
|
||||
CRGB c = CHSV(millis() / _color_freq, 200, 255);
|
||||
window->addPixelColor(x, y, &c);
|
||||
}
|
||||
|
||||
|
||||
boolean Blur2DEffect::can_be_shown_with_clock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Blur2DEffect::loop(uint16_t ms) {
|
||||
if (_count != settings.effects.blur2d.count) {
|
||||
_delete();
|
||||
_init();
|
||||
}
|
||||
uint8_t blur_amount = dim8_raw(beatsin8(3, 128, 224));
|
||||
window->blur(blur_amount);
|
||||
for (int i=0; i<_count; i++) {
|
||||
_blobs[i].render(window);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t x1 = beatsin8(7, 0, window->width-1);
|
||||
uint8_t y1 = beatsin8(11, 0, window->height-1);
|
||||
Blur2DEffect::Blur2DEffect() {
|
||||
_init();
|
||||
}
|
||||
|
||||
uint8_t x2 = beatsin8(13, 0, window->width-1);
|
||||
uint8_t y2 = beatsin8(8, 0, window->height-1);
|
||||
void Blur2DEffect::_init() {
|
||||
_count = settings.effects.blur2d.count;
|
||||
_blobs = new Blur2DBlob[_count];
|
||||
}
|
||||
|
||||
uint8_t x3 = beatsin8(11, 0, window->width-1);
|
||||
uint8_t y3 = beatsin8(13, 0, window->height-1);
|
||||
|
||||
uint16_t time = millis();
|
||||
CRGB c1 = CHSV(time / 29, 200, 255);
|
||||
CRGB c2 = CHSV(time / 41, 200, 255);
|
||||
CRGB c3 = CHSV(time / 73, 200, 255);
|
||||
window->addPixelColor(x1, y1, &c1);
|
||||
window->addPixelColor(x2, y2, &c2);
|
||||
window->addPixelColor(x3, y3, &c3);
|
||||
void Blur2DEffect::_delete() {
|
||||
delete[] _blobs;
|
||||
}
|
||||
|
||||
Blur2DEffect::~Blur2DEffect() {
|
||||
_delete();
|
||||
delete window;
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ Setting all_settings[] = {
|
||||
{"effects.big_clock.spacing", &settings.effects.big_clock.spacing, TYPE_UINT8},
|
||||
|
||||
{"effects.confetti.pixels_per_loop", &settings.effects.confetti.pixels_per_loop, TYPE_UINT8},
|
||||
|
||||
{"effects.blur2d.count", &settings.effects.blur2d.count, TYPE_UINT8},
|
||||
|
||||
{"effects.cycle.random", &settings.effects.cycle.random, TYPE_BOOL},
|
||||
{"effects.cycle.time", &settings.effects.cycle.time, TYPE_UINT16},
|
||||
@ -49,7 +51,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 = 30;
|
||||
const uint8_t all_settings_size = 31;
|
||||
|
||||
bool change_setting(const char* key, uint16_t new_value) {
|
||||
LOGln("Settings * Setting %s to new value %d.", key, new_value);
|
||||
|
Loading…
Reference in New Issue
Block a user