-
Notifications
You must be signed in to change notification settings - Fork 1
/
DisplayBarWaveForm.pde
104 lines (82 loc) · 2.28 KB
/
DisplayBarWaveForm.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
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
class LineB1 {
float weight = 3;
float sx, sy, ex, ey;
float alpha = 100;
LineB1(float startX, float startY, float endX, float endY) {
sx = startX;
sy = startY;
ex = endX;
ey = endY;
}
void draw(PGraphics g) {
color c = colorFromMap(int(sx), int(sy), true);
g.stroke(c, 215);
g.strokeWeight(this.weight);
g.line(sx, sy, ex, ey);
for(int i=0; i<(int)random(4,15); i++){
g.fill(c, alpha);
g.noStroke();
g.rect(random(sx,ex), random(sy,ey), random(1,4), random(1,6), 3);
}
}
}
class DisplayBarWaveForm extends AbstractDisplay {
int graphIndex;
int MAX_BALLS_PER_BAR = 64;
int MAX_BARS = NUM_SAMPLES_WAVE;
int MAX_BALLS = 100;
float maxWeight = 3;
final color C_PLACEHOLDER = color(101,113,106, 72);
float y1;
float y2;
float y1_10;
float y2_10;
float ph_space_width, space_width;
Easing [] easings;
DisplayBarWaveForm(ARect bound) {
super(bound);
y1 = bound.height * 0.47;
y2 = bound.height * 0.52;
y1_10 = bound.height * 0.45;
y2_10 = bound.height * 0.55;
space_width = bound.width / float(MAX_BARS);
ph_space_width = space_width / 5.0;
easings = new Easing [MAX_BARS];
for(int i=0; i< MAX_BARS; i++) {
easings[i] = new Easing();
easings[i].easing = 0.25;
easings[i].lastValue = 0.5;
}
}
void draw(PGraphics g) {
if (super.hidden) return;
PGraphics localG = createGraphics(g.width, g.height);
localG.beginDraw();
//draw this frame
for (int i=0; i< MAX_BARS; i++) {
easings[i].easing = _easingCtrlA;
float dataPoint = easings[i].ease(waveform.data[i]);
LineB1 ball = new LineB1(space_width *i,
g.height - map(dataPoint, -1, 1, g.height, 0),
space_width * i,
map(dataPoint, -1, 1, g.height, 0)
);
ball.weight = maxWeight + cvLinearToExp8(abs(dataPoint)) * 10;
ball.draw(localG);
}
localG.endDraw();
drawOn(localG, g, bound);
updateParams();
}
float _easingCtrlA, _alphaCtrlA;
void updateParams() {
maxWeight = mapCtrlA(0.7, 15);
_easingCtrlA = mapCtrlA(0.025,0.7);
_alphaCtrlA = mapCtrlA(200, 80);
}
void bang() {
for(int i=0; i< MAX_BARS; i++) {
easings[i].lastValue = i%2 == 0 ? -1:1;
}
}
}