-
Notifications
You must be signed in to change notification settings - Fork 0
/
RingDrawable.pde
65 lines (56 loc) · 1.09 KB
/
RingDrawable.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
class RingDrawable implements Drawable {
float w, h;
float x, y;
int[] a;
int max = Integer.MIN_VALUE;
float arcStep;
int c;
RingDrawable(float w, float h, int[] a, int c) {
this.w = w;
this.h = h;
this.a = new int[a.length];
for(int i = 0; i < a.length; i++) {
this.a[i] = a[i];
}
arcStep = w / a.length;
this.c = c;
}
void setup() {
for(int i = 0; i < a.length; i++) {
max = max(a[i], max);
}
}
void draw() {
pushMatrix();
pushStyle();
translate(x + w/2f, y + h/2f);
float arcRadians = QUARTER_PI;
for(int i = 0; i < a.length; i++) {
stroke(0);
float r = arcStep * i;
float start = ((float)a[i]/(float)max) * TWO_PI;
float end = start + arcRadians;
noFill();
strokeWeight(1f);
stroke(c);
arc(0, 0, r, r, start, end);
}
popStyle();
popMatrix();
}
void tick() {}
void place(Point p) {
this.x = p.x;
this.y = p.y;
}
float getWidth() { return w; }
float getHeight() { return h; }
void setColor(int clr) {
this.c = clr;
}
RingDrawable clone() {
RingDrawable d = new RingDrawable(w, h, a, c);
d.setup();
return d;
}
}