-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEffect_Sine.cpp
75 lines (67 loc) · 1.68 KB
/
Effect_Sine.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
// sine interference effect
//mode 0: sine 1 (red)
//mode 1: sine 2 (multi color)
//mode 2: sine 3 (variable color)
#ifndef EFFECTSINE_H
#define EFFECTSINE_H
#include "zEffectClass.h"
#include "LEDColorMgt.h"
class EffectSine : public EffectClass {
protected:
uint8_t _dist[M_WIDTH][M_HALFWIDTH];
int8_t _xoffset;
int8_t _yoffset;
uint16_t _freq;
uint16_t _speed;
uint8_t _color;
uint16_t _var;
public:
EffectSine(uint8_t _mode, Config_t *_cnf) : EffectClass(_mode) {
_cnf->currDelay = DELAY_NORMAL;
_cnf->currBright = NORMBRIGHT;
switch(_effectMode) {
case 0:
_xoffset = 1;
_yoffset = -4;
_freq = 5;
_speed = 2;
_color = 1;
_var = 0;
break;
case 1:
_xoffset = 1;
_yoffset = -5;
_freq = 6;
_speed = 2;
_color = 4;
_var = 550; // color variation
break;
case 2:
_xoffset = -8;
_yoffset = 6;
_freq = 7;
_speed = 2;
_color = 4;
_var = 0;
break;
}
uint8_t mlt256 = 256 / (M_HALFWIDTH + M_HEIGHT);
for(uint8_t y=0; y<M_HEIGHT; y++) {
for(uint8_t x=0; x<M_HALFWIDTH; x++) {
_dist[x][y] = sqrt((x+_xoffset)*(x+_xoffset) + (y+_yoffset)*(y+_yoffset)) * mlt256;
}
}
}
void step(Config_t *_cnf, CRGB* _leds) {
if(_effectMode == 2) {
_var = _cnf->currFrame;
}
for(uint8_t y=0; y<M_HEIGHT; y++) {
for(uint8_t x=0; x<M_HALFWIDTH; x++) {
_leds[XY(M_HALFWIDTH+x,y)] = _leds[XY(M_HALFWIDTH-x-1,y)] =
ColorMap(quadwave8(((_dist[x][y] * _freq) - (_cnf->currFrame * _speed)%256)),_color,_var);
}
}
}
};
#endif