Added FireEffect. Its values still need a bit of tweaking to look right...
This commit is contained in:
parent
96442b48cc
commit
f95589763e
@ -57,6 +57,9 @@
|
|||||||
#define EFFECT_SNAKE_DIRECTION_CHANGE 10
|
#define EFFECT_SNAKE_DIRECTION_CHANGE 10
|
||||||
#define EFFECT_SNAKE_SLOWDOWN 2
|
#define EFFECT_SNAKE_SLOWDOWN 2
|
||||||
|
|
||||||
|
#define EFFECT_FIRE_COOLDOWN 192
|
||||||
|
#define EFFECT_FIRE_SPARK_CHANCE 5
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define LOG(x) mqtt_log(x); Serial.print(x);
|
#define LOG(x) mqtt_log(x); Serial.print(x);
|
||||||
#define LOGln(x) mqtt_log_ln(x); Serial.println(x);
|
#define LOGln(x) mqtt_log_ln(x); Serial.println(x);
|
||||||
|
19
include/effect_fire.h
Normal file
19
include/effect_fire.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#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:
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
void loop();
|
||||||
|
};
|
54
src/effect_fire.cpp
Normal file
54
src/effect_fire.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#include "effect_fire.h"
|
||||||
|
#include "my_color_palettes.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "my_fastled.h"
|
||||||
|
#include "functions.h"
|
||||||
|
|
||||||
|
void FireEffect::start() {
|
||||||
|
this->data = new uint8_t[LED_COUNT];
|
||||||
|
for (int i=0; i<LED_COUNT; i++) this->data[i]=0;
|
||||||
|
for (int i=0; i<LED_WIDTH; i++) this->data[i]=this->spark_temp();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FireEffect::stop() {
|
||||||
|
delete [] this->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FireEffect::loop() {
|
||||||
|
cooldown();
|
||||||
|
spark();
|
||||||
|
propagate();
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FireEffect::cooldown() {
|
||||||
|
for(int i=0; i<LED_COUNT; i++) this->data[i] = scale8(this->data[i], EFFECT_FIRE_COOLDOWN); // 240 or something
|
||||||
|
}
|
||||||
|
|
||||||
|
void FireEffect::spark() {
|
||||||
|
for(int x=0; x<LED_WIDTH; x++) if (random8(EFFECT_FIRE_SPARK_CHANCE)==0) this->data[x] = this->spark_temp();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint8_t FireEffect::spark_temp() {
|
||||||
|
return random8(180, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FireEffect::propagate() {
|
||||||
|
for (int y=1; y<LED_HEIGHT; y++) for (int x=0; x<LED_WIDTH; x++) {
|
||||||
|
int index = y*LED_WIDTH + x;
|
||||||
|
uint8_t below_index = (y-1)*LED_WIDTH + x;
|
||||||
|
if (x==0) {
|
||||||
|
this->data[index] = scale8(this->data[below_index], 170) + scale8(this->data[below_index+1], 85);
|
||||||
|
} else if (x==LED_WIDTH-1) {
|
||||||
|
this->data[index] = scale8(this->data[below_index], 170) + scale8(this->data[below_index-1], 85);
|
||||||
|
} else {
|
||||||
|
this->data[index] = scale8(this->data[below_index], 128) + scale8(this->data[below_index-1], 64) + scale8(this->data[below_index+1], 64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FireEffect::draw() {
|
||||||
|
for (int y=1; y<LED_HEIGHT; y++) for (int x=0; x<LED_WIDTH; x++) {
|
||||||
|
setPixel(x, LED_HEIGHT - 1 - y, ColorFromPalette((CRGBPalette16) palette_fire, this->data[y*LED_WIDTH + x]));
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,7 @@
|
|||||||
#include "effect_cycle.h"
|
#include "effect_cycle.h"
|
||||||
#include "effect_confetti.h"
|
#include "effect_confetti.h"
|
||||||
#include "effect_snake.h"
|
#include "effect_snake.h"
|
||||||
|
#include "effect_fire.h"
|
||||||
|
|
||||||
SimpleList<EffectEntry>* effects;
|
SimpleList<EffectEntry>* effects;
|
||||||
SimpleList<Effect*>* cycle_effects;
|
SimpleList<Effect*>* cycle_effects;
|
||||||
@ -35,6 +36,7 @@ CycleEffect effect_cycle;
|
|||||||
TwirlEffect effect_twirl;
|
TwirlEffect effect_twirl;
|
||||||
ConfettiEffect effect_confetti;
|
ConfettiEffect effect_confetti;
|
||||||
SnakeEffect effect_snake;
|
SnakeEffect effect_snake;
|
||||||
|
FireEffect effect_fire;
|
||||||
|
|
||||||
Effect* current_effect;
|
Effect* current_effect;
|
||||||
|
|
||||||
@ -57,6 +59,7 @@ void setup_effects() {
|
|||||||
effects->add((EffectEntry){"heart", (Effect*)&effect_anim_heart});
|
effects->add((EffectEntry){"heart", (Effect*)&effect_anim_heart});
|
||||||
effects->add((EffectEntry){"confetti", (Effect *)&effect_confetti});
|
effects->add((EffectEntry){"confetti", (Effect *)&effect_confetti});
|
||||||
effects->add((EffectEntry){"snake", (Effect *)&effect_snake});
|
effects->add((EffectEntry){"snake", (Effect *)&effect_snake});
|
||||||
|
effects->add((EffectEntry){"fire", (Effect *)&effect_fire});
|
||||||
|
|
||||||
cycle_effects->add(&effect_sinematrix3);
|
cycle_effects->add(&effect_sinematrix3);
|
||||||
cycle_effects->add(&effect_single_dynamic);
|
cycle_effects->add(&effect_single_dynamic);
|
||||||
|
Loading…
Reference in New Issue
Block a user