-
Notifications
You must be signed in to change notification settings - Fork 1
/
radar.pde
58 lines (45 loc) · 1.27 KB
/
radar.pde
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
class RadarRenderer extends AudioRenderer {
float aura = 2;
float orbit = .4;
int delay = 3;
int rotations;
RadarRenderer(AudioSource source) {
rotations = (int) source.sampleRate() / source.bufferSize();
}
void setup() {
colorMode(HSB, TWO_PI * rotations, 1, 1);
background(0);
}
synchronized void draw()
{
colorMode(HSB, 40 * rotations, 1, 1);
if (left != null) {
float t = map(millis(), 0, delay * 800, 0, PI);
int n = left.length;
// center
float w = width/2 + cos(t) * width * orbit;
float h = height/2 + sin(t) * height * orbit;
// size of the aura
float w2 = width * aura, h2 = height * aura;
// smoke effect
if (frameCount % delay == 0 ) image(g, 0, 0, width+1, height+1);
// draw polar curve
float r1=0, a1=0, x1=0, y1=0, r2=0, a2=0, x2=0, y2=0;
for (int i=0; i <= n; i++)
{
r1 = r2;
a1 = a2;
x1 = x2;
y1 = y2;
r2 = left[i % n] ;
a2 = map(i, 0, n, 0, TWO_PI * rotations);
x2 = w + cos(a2) * r2 * w2;
y2 = h + sin(a2) * r2 * h2;
stroke(a1, 1, 1, 30);
// strokeWeight(dist(x1,y1,x2,y2) / 4);
if (i>0) line(x1, y1, x2, y2);
}
}
colorMode(RGB,255);
}
}