Added FireworkEffect, which needs a lot more tweaking.

This commit is contained in:
Fabian Schlenz 2019-06-05 06:27:55 +02:00
parent de180b9b28
commit a2b0f7106f
4 changed files with 67 additions and 10 deletions

View File

@ -0,0 +1,7 @@
#pragma once
#include "Effect.h"
class FireworkEffect : public Effect {
void loop();
};

View File

@ -5,7 +5,7 @@
#include "my_fastled.h" #include "my_fastled.h"
#include "config.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); void setPixel(int x, int y, CRGB color);
@ -21,6 +21,12 @@ void clear(Window window);
void clear(); 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) { inline double sines(double x, double y) {
return ((cos(x) * sin(y)) * 0.5) + 0.5; return ((cos(x) * sin(y)) * 0.5) + 0.5;
} }

11
src/effect_firework.cpp Normal file
View File

@ -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);
}

View File

@ -2,7 +2,7 @@
#include "prototypes.h" #include "prototypes.h"
#include "my_fastled.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 ( x >= LED_WIDTH) return 0;
if ( y >= LED_HEIGHT) return 0; if ( y >= LED_HEIGHT) return 0;
if ( x < 0) return 0; if ( x < 0) return 0;
@ -25,15 +25,9 @@ void setPixel(int x, int y, CRGB color) {
if ( x < 0) return; if ( x < 0) return;
if ( y < 0) return; if ( y < 0) return;
// Invert y uint16_t index = XYsafe(x, y);
y = LED_HEIGHT - 1 - y;
if (y & 1) x = LED_WIDTH - 1 - x; leds[index] = color;
// Invert x
//x = LED_WIDTH - 1 - x;
leds[y*LED_WIDTH+x] = color;
} }
void setPixel(int i, CRGB color) { void setPixel(int i, CRGB color) {
@ -68,6 +62,45 @@ void clear() {
clear(w); clear(w);
} }
void blur(fract8 blur_amount) {
// Based on FastLED code
for (uint8_t i=0; i<LED_HEIGHT; i++) blur_row(i, blur_amount);
for (uint8_t i=0; i<LED_WIDTH; i++) blur_column(i, blur_amount);
}
void blur_row(uint8_t row_index, fract8 blur_amount) {
CRGB* row = &leds[row_index * LED_WIDTH];
uint8_t keep = 255 - blur_amount;
uint8_t seep = 17; // 15 is zu wenig
CRGB carryover = CRGB::Black;
for (uint8_t x=0; x<LED_WIDTH; x++) {
CRGB currentColor = row[x];
CRGB part = currentColor;
part.nscale8(seep);
currentColor.nscale8(keep);
currentColor += carryover;
if (x>0) 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; y<LED_HEIGHT; y++) {
CRGB currentColor = leds[XYsafe(col_index, y)];
CRGB part = currentColor;
part.nscale8(seep);
currentColor.nscale8(keep);
currentColor += carryover;
if (y>0) leds[XYsafe(col_index, y-1)]+=part;
leds[XYsafe(col_index, y)]=currentColor;
carryover = part;
}
}
struct Matrix multiply(struct Matrix m1, struct Matrix m2) { struct Matrix multiply(struct Matrix m1, struct Matrix m2) {