-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBannerDrawable.pde
More file actions
72 lines (64 loc) · 1.65 KB
/
BannerDrawable.pde
File metadata and controls
72 lines (64 loc) · 1.65 KB
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
class BannerDrawable implements Drawable {
boolean[] state;
float[] alpha;
float w, noteHeight, x, y;
int positiveColor, negativeColor;
float negWeight, posWeight;
BannerDrawable(float w, float noteHeight, int[] snapshot, int[] sorted, int negativeColor, int positiveColor, float negWeight, float posWeight) {
this.w = w;
this.noteHeight = noteHeight;
this.positiveColor = positiveColor;
this.negativeColor = negativeColor;
state = new boolean[snapshot.length];
alpha = new float[snapshot.length];
int max = sorted[sorted.length-1];
for(int i = 0; i < snapshot.length; i++) {
state[i] = snapshot[i] == sorted[i];
alpha[i] = (float)snapshot[i]/(float)max;
}
this.negWeight = negWeight;
this.posWeight = posWeight;
}
public void setup() { }
public void tick() {
}
public void draw() {
pushMatrix();
translate(x, y);
pushStyle();
noFill();
strokeCap(SQUARE);
for(int i = 0; i < state.length; i++) {
float noteY = i * noteHeight + 0.5;
float sw = state[i] ? posWeight : negWeight;
int sc = state[i] ? positiveColor : negativeColor;
if(false) {
strokeWeight(sw);
stroke(sc);
line(0, noteY, w, noteY);
}
else if(true) {
noStroke();
fill(red(sc), green(sc), blue(sc), alpha(sc) * alpha[i]);
rect(0, noteY, w, noteHeight);
}
else {
noStroke();
fill(red(sc), green(sc), blue(sc), alpha(sc) * alpha[i]);
ellipse(0, noteY, w*alpha[i]*1.1f, noteHeight*alpha[i]*1.1f);
}
}
popStyle();
popMatrix();
}
public void place(Point p) {
this.x = p.x;
this.y = p.y;
}
public float getWidth() {
return w;
}
public float getHeight() {
return state.length * noteHeight;
}
}