From a2b0f7106fb84eef933d246048057dac7dd1ef7d Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Wed, 5 Jun 2019 06:27:55 +0200 Subject: [PATCH] Added FireworkEffect, which needs a lot more tweaking. --- include/effect_firework.h | 7 ++++++ include/functions.h | 8 +++++- src/effect_firework.cpp | 11 +++++++++ src/functions.cpp | 51 ++++++++++++++++++++++++++++++++------- 4 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 include/effect_firework.h create mode 100644 src/effect_firework.cpp diff --git a/include/effect_firework.h b/include/effect_firework.h new file mode 100644 index 0000000..fbaa2b0 --- /dev/null +++ b/include/effect_firework.h @@ -0,0 +1,7 @@ +#pragma once + +#include "Effect.h" + +class FireworkEffect : public Effect { + void loop(); +}; diff --git a/include/functions.h b/include/functions.h index e31befd..c9bb803 100644 --- a/include/functions.h +++ b/include/functions.h @@ -5,7 +5,7 @@ #include "my_fastled.h" #include "config.h" -int XYsafe(int x, int y); +uint16_t XYsafe(int x, int y); void setPixel(int x, int y, CRGB color); @@ -21,6 +21,12 @@ void clear(Window window); void clear(); +void blur(fract8 blur_amount); + +void blur_row(uint8_t row_index, fract8 blur_amount); + +void blur_column(uint8_t column_index, fract8 blur_amount); + inline double sines(double x, double y) { return ((cos(x) * sin(y)) * 0.5) + 0.5; } diff --git a/src/effect_firework.cpp b/src/effect_firework.cpp new file mode 100644 index 0000000..7b21edb --- /dev/null +++ b/src/effect_firework.cpp @@ -0,0 +1,11 @@ +#include "effect_firework.h" +#include "my_fastled.h" +#include "functions.h" +#include "config.h" + +void FireworkEffect::loop() { + if (random8(EFFECT_FIREWORK_SHOT_CHANCE)==0) { + leds[random16(LED_COUNT)] = CHSV(random8(), 255, 255); + } + blur(EFFECT_FIREWORK_BLUR); +} diff --git a/src/functions.cpp b/src/functions.cpp index a0ecda7..ac50a93 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -2,7 +2,7 @@ #include "prototypes.h" #include "my_fastled.h" -int XYsafe(int x, int y) { +uint16_t XYsafe(int x, int y) { if ( x >= LED_WIDTH) return 0; if ( y >= LED_HEIGHT) return 0; if ( x < 0) return 0; @@ -25,15 +25,9 @@ void setPixel(int x, int y, CRGB color) { if ( x < 0) return; if ( y < 0) return; - // Invert y - y = LED_HEIGHT - 1 - y; + uint16_t index = XYsafe(x, y); - if (y & 1) x = LED_WIDTH - 1 - x; - - // Invert x - //x = LED_WIDTH - 1 - x; - - leds[y*LED_WIDTH+x] = color; + leds[index] = color; } void setPixel(int i, CRGB color) { @@ -68,6 +62,45 @@ void clear() { clear(w); } +void blur(fract8 blur_amount) { + // Based on FastLED code + for (uint8_t i=0; i0) row[x-1]+=part; + row[x]=currentColor; + carryover = part; + } +} + +void blur_column(uint8_t col_index, fract8 blur_amount) { + uint8_t keep = 255 - blur_amount; + uint8_t seep = 17; + CRGB carryover = CRGB::Black; + for (uint8_t y=0; y0) leds[XYsafe(col_index, y-1)]+=part; + leds[XYsafe(col_index, y)]=currentColor; + carryover = part; + } +} + struct Matrix multiply(struct Matrix m1, struct Matrix m2) {