-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPatternAudio_Z_Circles.h
251 lines (179 loc) · 7.22 KB
/
PatternAudio_Z_Circles.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
* 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 PatternAudioCircles_H
#define PatternAudioCircles_H
class TestCircle{
public:
char* name;
byte theta1 = 0;
byte theta2 = 0;
byte hueoffset = 0;
uint8_t radiusx = MATRIX_WIDTH / 4;
uint8_t radiusy = MATRIX_HEIGHT / 4;
uint8_t minx = MATRIX_CENTER_X - radiusx;
uint8_t maxx = MATRIX_CENTER_X + radiusx + 1;
uint8_t miny = MATRIX_CENTER_Y - radiusy;
uint8_t maxy = MATRIX_CENTER_Y + radiusy + 1;
uint8_t spirocount = 32;
uint8_t spirooffset = 256 / spirocount;
boolean spiroincrement = true;
boolean change = false;
};
class PatternAudioCircles : public Drawable {
private:
static const uint8_t CIRCLE_COUNT = 3;
TestCircle testCircle[CIRCLE_COUNT];
//byte theta1 = 0;
//byte theta2 = 0;
//byte hueoffset = 0;
bool cycleColors;
uint8_t color1 = 0;
uint8_t color2 = 64;
uint8_t color3 = 128;
uint8_t color4 = 192;
public:
PatternAudioCircles() {
name = (char *)"Audio Circles";
id2 = 1;
}
//uint8_t radiusx = MATRIX_WIDTH / 4;
//uint8_t radiusy = MATRIX_HEIGHT / 4;
//uint8_t minx = (MATRIX_CENTER_X - radiusx) / 2;
//uint8_t maxx = MATRIX_CENTER_X + radiusx + 1;
//uint8_t miny = (MATRIX_CENTER_Y - radiusy) / 2;
//uint8_t maxy = MATRIX_CENTER_Y + radiusy + 1;
//uint8_t spirocount = 32;
//uint8_t spirooffset = 256 / spirocount;
//boolean spiroincrement = true;
bool insideOut = false;
uint8_t caleidoscopeMode = 0;
// #############
// ### START ###
// #############
void start(uint8_t _pattern){
cycleColors = random(0, 2);
caleidoscopeMode = random(0, 2);
insideOut = random(0, 2);
// override for testing
cycleColors = false;
caleidoscopeMode = 1;
for (int c = 0; c < CIRCLE_COUNT; c++){
if (caleidoscopeMode == 1) {
testCircle[c].radiusx = (MATRIX_WIDTH / 4) / 2;
testCircle[c].radiusy = (MATRIX_HEIGHT / 4) /2;
testCircle[c].minx = (MATRIX_CENTER_X /2) - testCircle[c].radiusx;
testCircle[c].maxx = (MATRIX_CENTER_X /2) + testCircle[c].radiusx + 1;
testCircle[c].miny = (MATRIX_CENTER_Y /2) - testCircle[c].radiusy;
testCircle[c].maxy = (MATRIX_CENTER_Y /2) + testCircle[c].radiusy + 1;
testCircle[c].spirocount = 32;
testCircle[c].spirooffset = 256 / testCircle[c].spirocount;
testCircle[c].spiroincrement = true;
}
else {
testCircle[c].radiusx = MATRIX_WIDTH / 4;
testCircle[c].radiusy = MATRIX_HEIGHT / 4;
testCircle[c].minx = (MATRIX_CENTER_X - testCircle[c].radiusx) / 2;
testCircle[c].maxx = MATRIX_CENTER_X + testCircle[c].radiusx + 1;
testCircle[c].miny = (MATRIX_CENTER_Y - testCircle[c].radiusy) / 2;
testCircle[c].maxy = MATRIX_CENTER_Y + testCircle[c].radiusy + 1;
testCircle[c].spirocount = 32;
testCircle[c].spirooffset = 256 / testCircle[c].spirocount;
testCircle[c].spiroincrement = true;
}
}
};
// ##################
// ### DRAW FRAME ###
// ##################
unsigned int drawFrame(uint8_t _pattern, uint8_t _total) {
boolean change = false;
byte data;
for (int c = 0; c < CIRCLE_COUNT; c++){
//testCircle[c].theta1++;
//testCircle[c].theta1 = serialData.specData8[c+1];
data = fftData.specData8[c+1];
if (data > 127) data = 127;
data = data * 2;
if (insideOut) data = 255 - data;
testCircle[c].theta1 = data;
for (int i = 0; i < testCircle[c].spirocount; i++) {
uint8_t x0 = mapsin8(testCircle[c].theta1 + i * testCircle[c].spirooffset, testCircle[c].minx, testCircle[c].maxx);
uint8_t y0 = mapcos8(testCircle[c].theta1 + i * testCircle[c].spirooffset, testCircle[c].miny, testCircle[c].maxy);
uint8_t x1 = mapsin8(testCircle[c].theta2 + i * testCircle[c].spirooffset, x0 - testCircle[c].radiusx, x0 + testCircle[c].radiusx);
uint8_t y1 = mapcos8(testCircle[c].theta2 + i * testCircle[c].spirooffset, y0 - testCircle[c].radiusy, y0 + testCircle[c].radiusy);
CRGB color = effects.ColorFromCurrentPalette(testCircle[c].hueoffset + i * testCircle[c].spirooffset, 128);
// test colors
//color = dma_display->color565(128+(i*32), 128+(i*32), 128+(i*32));
color = effects.ColorFromCurrentPalette(data * 2);; // dma_display->color565(16*i, 32*i, 64*i);
if (fftData.specData8[c+1] > 0)
effects.leds[XY(x1, y1)] += color;
if((x1 == MATRIX_CENTER_X && y1 == MATRIX_CENTER_Y) ||
(x1 == MATRIX_CENTER_X && y1 == MATRIX_CENTER_Y)) testCircle[c].change = true;
// randomise this?
//testCircle[c].theta2++;
}
}
/* old method
theta1++;
theta1 = serialData.specData8[3];
if (cycleColors) {
color1++;
color2++;
color3++;
color4++;
}
else {
color1 = 0;
color2 = 64;
color3 = 128;
color4 = 192;
}
for (int i = 0; i < spirocount; i++) {
uint8_t x0 = mapsin8(theta1 + i * spirooffset, minx, maxx);
uint8_t y0 = mapcos8(theta1 + i * spirooffset, miny, maxy);
uint8_t x1 = mapsin8(theta2 + i * spirooffset, x0 - radiusx, x0 + radiusx);
uint8_t y1 = mapcos8(theta2 + i * spirooffset, y0 - radiusy, y0 + radiusy);
CRGB color = effects.ColorFromCurrentPalette(hueoffset + i * spirooffset, 128);
effects.leds[XY(x1, y1)] += color;
if((x1 == MATRIX_CENTER_X && y1 == MATRIX_CENTER_Y) ||
(x1 == MATRIX_CENTRE_X && y1 == MATRIX_CENTRE_Y)) change = true;
}
*/
switch (caleidoscopeMode) {
case 0:
effects.Caleidoscope1();
break;
case 1:
effects.Caleidoscope2(); // 2 = good
break;
case 2:
effects.Expand(31,31,16,250); // 1 = good
break;
default:
break;
}
//effects.SpiralStream(31, 15, 64, 128); // for 64 pixel wide matrix!
effects.DimAll(250);
return 0;
}
};
#endif