-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPatternAudio_A_RotatingWave.h
185 lines (145 loc) · 5.18 KB
/
PatternAudio_A_RotatingWave.h
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Aurora: https://github.com/pixelmatix/aurora
* Copyright (c) 2014 Jason Coon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef PatternAudioRotatingWave_H
#define PatternAudioRotatingWave_H
class PatternAudioRotatingWave : public Drawable {
private:
int x1,y1,x2,y2;
Point p1,p2;
Point rp1,rp2;
byte audio1;
byte audio2;
uint8_t audioScale;
// randomise these
float angle = -1;
float direction;
bool rotate;
bool caleidoscope;
uint8_t caleidoscopeEffect;
uint8_t dimVal;
uint8_t dimStart;
uint8_t dimEnd;
public:
PatternAudioRotatingWave() {
name = (char *)"Rotating Wave";
id = "A";
enabled = true;
}
// ------------------ start -------------------
void start(uint8_t _pattern) {
rotate = random8(0,2);
if (angle == -1) angle = 0;
direction = 0.01;
if (random8(0,2)) direction = -direction;
audioScale = random8(3,6);
caleidoscope = random8(0, 5); // 80% chance of caleidoscope
caleidoscopeEffect = random8(1, CALEIDOSCOPE_COUNT + 1);
dimStart = 255;
dimEnd = random8(0, 180);
dimVal = dimStart;
}
// --------------------- DRAW FRAME -------------------------
unsigned int drawFrame(uint8_t _pattern, uint8_t _total) {
//effects.DimAll(180); // looks good with 0
//blur2d(effects.leds, MATRIX_WIDTH > 255 ? 255 : MATRIX_WIDTH, MATRIX_HEIGHT > 255 ? 255 : MATRIX_HEIGHT, 255);
// if we are going to dim all, then do it gradually
effects.DimAll(dimVal);
if (dimVal > dimEnd) dimVal--;
if (!fftData.noAudio)
{
/*
// from top down
if (true == true)
{
for (byte i = 0; i < MATRIX_WIDTH - 1 + 16; i++)
{
audio1 = fftData.specData[i] / 3;
audio2 = fftData.specData[i+1] / 3;
x1 = i - 8;
y1 = audio1;
x2 = i+1 - 8;
y2 = audio2;
Point p1(x1,y1);
Point p2(x2,y2);
Point rp1 = effects.RotatePoint(31,31,angle,p1);
Point rp2 = effects.RotatePoint(31,31,angle,p2);
effects.BresenhamLine(rp1.x, rp1.y, rp2.x, rp2.y, dma_display->color565(128, 128, 128));
}
}
*/
// from top down backwards
if (true == true)
{
for (byte i = 0; i < MATRIX_WIDTH - 1 + 16; i++)
{
audio1 = fftData.specData[i] / audioScale;
audio2 = fftData.specData[i+1] / audioScale;
x1 = (MATRIX_WIDTH + 16) - i - 8;
y1 = audio1;
x2 = (MATRIX_WIDTH + 16) - i-1 - 8;
y2 = audio2;
Point p1(x1,y1);
Point p2(x2,y2);
Point rp1 = effects.RotatePoint(31,31,angle,p1);
Point rp2 = effects.RotatePoint(31,31,angle,p2);
effects.BresenhamLine(rp1.x, rp1.y, rp2.x, rp2.y, effects.ColorFromCurrentPalette(i*3));
}
}
// from bottom up
if (true == true)
{
for (byte i = 0; i < MATRIX_WIDTH - 1 + 16; i++)
{
audio1 = fftData.specData[i] / 3;
audio2 = fftData.specData[i+1] / 3;
x1 = i - 8;
y1 = MATRIX_HEIGHT - audio1;
x2 = i+1 - 8;
y2 = MATRIX_HEIGHT - audio2;
Point p1(x1,y1);
Point p2(x2,y2);
Point rp1 = effects.RotatePoint(31,31,angle,p1);
Point rp2 = effects.RotatePoint(31,31,angle,p2);
effects.BresenhamLine(rp1.x, rp1.y, rp2.x, rp2.y, effects.ColorFromCurrentPalette(i*3));
}
}
}
// do caleidoscope sometimes
if (caleidoscope) {
effects.RandomCaleidoscope(caleidoscopeEffect);
}
if (rotate)
{
angle = angle + direction;
if (angle >= 3.14*2) angle = 0;
}
// simple test
//for (byte i = 0; i < MATRIX_WIDTH - 1; i++)
//{
// audio1 = fftData.specData[i] / 3;
// audio2 = fftData.specData[i+1] / 3;
// effects.BresenhamLine(i, audio1, i+1, audio2, dma_display->color565(128, 128, 128));
//}
return 0;
}
};
#endif