-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathanim_spread.cpp
36 lines (31 loc) · 885 Bytes
/
anim_spread.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
#include "anim.h"
#include "color.h"
#include "palette.h"
#define SPREAD_MAX_WIDTH 20
void Anim::animSpread_SetUp() {
inc = random(2,8);
memset(seq, 0, LEDS);
}
void Anim::animSpread_Run() {
memset(leds, 0, 3*LEDS);
for (int i=0;i<LEDS;i++) {
if (seq[i] > 0) {
byte width = SPREAD_MAX_WIDTH - seq[i];
for (int j=i-width;j<=(i+width);j++) {
Color c = ledstmp[i];
if (j>=0 && j<LEDS) {
leds[j].r += c.r;
leds[j].g += c.g;
leds[j].b += c.b;
}
}
ledstmp[i].fade(255/SPREAD_MAX_WIDTH);
seq[i]--;
}
}
if (random(inc) == 0) {
byte pos = random(0,LEDS);
ledstmp[pos] = palette->getPalColor((float)rngb()/256);
seq[pos] = SPREAD_MAX_WIDTH;
}
}