-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrain.cpp
More file actions
101 lines (90 loc) · 4.65 KB
/
rain.cpp
File metadata and controls
101 lines (90 loc) · 4.65 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <arduino.h>
#include <stdint.h>
#include "rain.h"
const int16_t raintab0[392]={50,38,26,13,74,62,5,0,1,2,3,4,9,19,15,111,116,98,24,24,25,22,16,16,17,23,30,28,124,123,29,29,
36,124,124,29,29,43,44,40,148,153,135,42,43,49,47,41,41,48,54,52,161,160,53,53,60,161,161,53,53,67,68,64,
185,190,172,66,67,73,71,65,65,72,78,76,86,85,77,77,84,86,86,77,77,91,93,98,209,208,202,96,97,94,88,209,
89,95,103,105,222,221,107,107,108,106,221,210,101,114,116,118,129,239,233,114,115,116,119,113,114,115,240,129,131,135,246,245,
127,128,134,132,126,246,133,140,142,259,258,144,144,145,143,258,247,138,151,153,155,166,276,270,151,152,153,156,150,151,152,277,
166,168,172,283,282,164,165,171,169,163,283,170,177,179,296,295,181,181,182,180,295,284,175,188,190,192,91,201,200,188,189,190,
193,187,188,189,206,214,309,309,199,205,203,198,309,199,204,212,214,216,227,321,320,212,213,219,217,211,321,218,225,227,228,237,
339,332,225,226,232,232,231,339,231,237,243,251,334,334,237,238,241,236,334,242,249,251,253,264,345,344,249,250,256,254,248,345,
255,262,264,265,274,363,356,262,263,269,269,268,363,268,274,280,288,358,358,274,275,278,273,358,279,286,288,290,301,369,368,286,
287,293,291,285,369,292,299,301,302,199,314,307,299,300,306,306,305,314,305,312,314,316,324,381,381,318,313,319,317,311,381,318,
324,330,323,382,382,329,329,323,323,382,329,383,331,339,341,348,383,383,337,338,343,342,336,337,348,354,347,384,384,353,353,347,
347,384,353,379,355,363,365,372,379,379,361,362,367,366,360,361,372,378,371,380,380,377,377,371,371,380,377,386,387,388,389,390,
385,391,391,391,391,391,391,-1};
const int16_t raintab1[392]={39,27,14,75,63,51,0,1,2,3,4,5,9,18,21,22,99,94,86,24,25,22,16,17,17,23,30,28,29,112,111,111,
36,29,29,111,29,124,37,46,47,136,132,42,43,49,47,41,42,48,54,52,53,149,148,148,60,53,53,148,53,161,61,70,
71,173,169,66,67,73,71,65,66,72,78,76,77,186,185,185,84,77,77,185,77,193,92,94,89,197,202,90,91,94,95,89,
89,95,103,105,106,210,209,107,108,106,221,210,101,222,99,117,119,239,223,222,109,116,121,120,114,115,240,119,130,132,127,235,
127,122,129,132,133,127,133,140,142,143,247,246,144,145,143,258,247,138,259,136,154,156,276,260,259,146,153,158,157,151,152,277,
156,167,169,164,272,164,159,166,169,170,164,170,177,179,180,284,283,181,182,180,295,284,175,296,173,191,193,201,297,296,183,190,
195,194,188,189,206,198,308,308,304,205,203,198,308,199,204,316,198,216,217,212,310,316,213,219,219,218,212,213,321,217,228,230,
225,322,321,220,227,232,231,225,226,230,243,236,333,333,237,238,241,236,333,242,341,236,253,254,249,335,341,250,256,256,255,249,
250,345,254,265,267,262,346,345,257,264,269,268,262,263,267,280,273,357,357,274,275,278,273,357,279,365,273,290,291,286,359,365,
287,293,293,292,286,287,369,291,302,304,299,370,369,294,301,306,305,299,300,371,314,316,311,380,380,312,313,319,317,318,380,318,
324,330,323,381,381,324,324,329,329,381,329,382,323,339,341,336,382,382,331,338,343,342,337,337,348,354,347,383,383,348,348,353,
353,383,353,384,347,363,365,360,384,384,355,362,367,366,361,361,372,378,371,379,379,372,372,377,377,379,377,385,386,387,388,389,
390,391,391,391,391,391,391,-1};
rain::rain():effect("Rain",0) {
sparcN = newintparam("N", 1, 20, 3);
col = newcolparam("Col", 0, 0, 255);
useglobalcol = newboolparam("global", true);
decay = newintparam("decay", 0, 4, 0);
globalcol = NULL;
}
void rain::setGlobalCol(colorgen *_col) {
globalcol = _col;
}
inline uint8_t add8(uint8_t a, uint8_t b) {
uint16_t sum = (uint16_t) a + b;
return (sum > 255)?255:sum;
}
void rain::tick() {
uint8_t r, g, b;
// Decay
listdecay(decay->d.i.val);
// flow down
const int16_t *raintab = raintab0;
if ((rand() % 2) == 0)
raintab = raintab1;
for (int y=0;y < LEDH-1;y++) {
for (int x=0;x<LEDW;x++) {
int led = bandtable[y*LEDW+x];
if (led >= 0) {
if (list->r[led] || list->g[led] || list->b[led]) { // is set
int rainto = raintab[led];
if (rainto >= 0) {
list->r[rainto] = add8(list->r[rainto], list->r[led]);
list->g[rainto] = add8(list->g[rainto], list->g[led]);
list->b[rainto] = add8(list->b[rainto], list->b[led]);
list->r[led]=0; // >>=2;
list->g[led]=0; // >>=2;
list->b[led]=0; // >>=2;
}
}
}
}
}
// New drops
if (useglobalcol->d.b.val && globalcol) {
r = globalcol->r;
g = globalcol->g;
b = globalcol->b;
} else {
r = col->d.c.r;
g = col->d.c.g;
b = col->d.c.b;
}
int i=0;
while (i<sparcN->d.i.val) {
uint32_t idx = rand() % LEDS;
if (thetatable[idx] > 9) {
i++;
list->r[idx]=r;
list->g[idx]=g;
list->b[idx]=b;
}
}
}