-
Notifications
You must be signed in to change notification settings - Fork 0
/
FireworksEffect.cpp
86 lines (75 loc) · 2.18 KB
/
FireworksEffect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "FireworksEffect.h"
#include "FastLED.h"
FireworksEffect::FireworksEffect(CRGB* leds, const uint8_t num_leds)
: NendoEffect(leds, num_leds)
, fireworks_update(50, 1)
, new_fireworks_update(16, 1)
, brightness_update(16, 1)
, bg_update(100, 1)
{
for (uint8_t i = 0; i < MAX_FIREWORKS; ++i)
{
ActiveFireworks[i].state = 0;
}
}
int FireworksEffect::GetUid()
{
return 2000;
}
void FireworksEffect::add_firework()
{
for (uint8_t i = 0; i < MAX_FIREWORKS; ++i) {
if (ActiveFireworks[i].state == 0) {
uint8_t width = random8() % 6 + 1;
ActiveFireworks[i].width = width;
ActiveFireworks[i].location = width + random8() % (m_num_leds - width * 2);
ActiveFireworks[i].color = random8();
ActiveFireworks[i].state = ActiveFireworks[i].width;
return;
}
}
}
void FireworksEffect::update_firework(uint8_t i)
{
uint8_t dist = ActiveFireworks[i].width - ActiveFireworks[i].state;
// for (uint8_t loc = ActiveFireworks[i].location - dist; loc <= ActiveFireworks[i].location + dist; ++loc)
// leds[loc] = CHSV(ActiveFireworks[i].color, 255, 255);
m_leds[ActiveFireworks[i].location + dist] = CHSV(ActiveFireworks[i].color, 255, 255);
m_leds[ActiveFireworks[i].location - dist] = CHSV(ActiveFireworks[i].color, 255, 255);
ActiveFireworks[i].state--;
}
bool FireworksEffect::Update()
{
bool something_changed = false;
if (bg_update.check() == 1)
{
background_color.h++;
}
if (brightness_update.check() == 1)
{
for(int i = 0; i < m_num_leds; i++) {
//m_leds[i].fadeToBlackBy(fade_rate);
m_leds[i] = blend(m_leds[i], CRGB(background_color), fade_rate);
}
something_changed = true;
}
if (new_fireworks_update.check() == 1) {
add_firework();
new_fireworks_update.interval(random16() % 1500);
fireworks_update.interval((random8() % 100) + 10);
fade_rate = (random8() % 10) + 5;
new_fireworks_update.reset();
something_changed = true;
}
if (fireworks_update.check())
{
for (uint8_t i = 0; i < MAX_FIREWORKS; ++i) {
if (ActiveFireworks[i].state != 0)
{
update_firework(i);
}
}
something_changed = true;
}
return something_changed;
}