-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPatternAudio_XR_Torus.h
155 lines (118 loc) · 4.91 KB
/
PatternAudio_XR_Torus.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
/*
* 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 PatternAudioTorus_H
#define PatternAudioTorus_H
class PatternAudioTorus : public Drawable {
private:
// used for internal colour cycling
uint8_t color1 = 0;
uint8_t color2 = 64;
uint8_t color3 = 128;
uint8_t color4 = 192;
// used for internal audio calcs
byte audioData;
uint8_t maxData = 127;
// pattern specific parameters used for randomizing, theses are mostly radomized at initial start and
// determine the style of backdrop and main effects to render
bool cycleColors = true; // cylce through the color spectrum or not
bool caleidoscope = false;
uint8_t caleidoscopeEffect = 0;
bool dimAll = false;
uint8_t dimAmount = 0;
public:
PatternAudioTorus() {
name = (char *)"Torus";
id = (char *)"R";
enabled = true;
}
// #------------- START -------------#
void start(uint8_t _order) {
// randomize the effects to use
cycleColors = random8(0, 3); // 75% of the time, the color palette will be cycled
caleidoscope = random8(0, 2); // 50% chance of caleidoscope
caleidoscopeEffect = random8(1, CALEIDOSCOPE_COUNT + 1);
if (caleidoscopeEffect==5) caleidoscopeEffect = 3;
dimAll = random8(0, 10); // 90% chance of dimming the output render
dimAmount = random8(200, 240);
};
uint8_t theta1 = 0;
uint8_t theta2 = 0;
uint8_t minx = 16;
uint8_t miny = 16;
uint8_t maxx = 48;
uint8_t maxy = 48;
uint8_t spirooffset = 16; // 32= hexagon, 16=
uint8_t radiusx = 8;
uint8_t radiusy = 12;
uint8_t hueoffset = 0;
uint8_t lastx = 0;
uint8_t lasty = 0;
// #------------- DRAW FRAME -------------#
unsigned int drawFrame(uint8_t _order, uint8_t _total) {
// order - indicates the order in which the effect is being drawn, patterns can use the appropriate pre and post effects, if any, depending on order etc.
// total - the total number of audio effect animations being played simultaineously
// this patterns looks good with dimming so do it sometimes
if (dimAll) {
effects.DimAll(dimAmount);
}
// general cyclic stuff
if (cycleColors) {
// currently cycling through colours as fast as possible
color1++;
color2++;
}
// brightness = LO
byte audio = fftData.specData8[6];
if (audio > 63) audio = 63;
audio = audio * 4;
// scale audio data to floor at specDataMinVolume
// draw to half width canvas
effects.ClearCanvas(1);
CRGB color;
uint8_t x1,y1,x2,y2;
for (int i = 0; i < 17; i++) {
// determine brightness from
x1 = mapsin8(theta1 + i * spirooffset, minx, maxx);
y1 = mapcos8(theta1 + i * spirooffset, miny, maxy);
x2 = mapsin8(theta2 + i * spirooffset, x1 - radiusx, x1 + radiusx);
y2 = mapcos8(theta2 + i * spirooffset, y1 - radiusy, y1 + radiusy);
color = effects.ColorFromCurrentPalette(hueoffset + i * spirooffset, audio);
// scale audio data to floor at specDataMinVolume
audio = fftData.specData[i*5];
if (audio > 127) audio - 127;
audio = (audio - fftData.specDataMinVolume) * 2;
if (i > 0) effects.BresLineCanvasH(effects.canvasH, lastx/2, lasty/2, x2/2, y2/2, effects.ColorFromCurrentPalette(hueoffset + i * spirooffset, audio));
effects.ApplyCanvasH(effects.canvasH, (x1/2)-8, (y1/2)-8, 1.5);
lastx = x2;
lasty = y2;
}
theta1 = theta1 + 2;
theta2++;
hueoffset++;
// do caleidoscope sometimes
if (caleidoscope) {
effects.RandomCaleidoscope(caleidoscopeEffect);
}
return 0;
}
};
#endif