> show canvas only <
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
/* built with Studio Sketchpad:
 *
 * observe the evolution of this sketch:
 *
 * authors:
 *   GoToLoop
 
 * license (unless otherwise specified):
 *   creative commons attribution-share alike 3.0 license.
 */
 
 
 
/**
 * DrawPieChart (v2.07)
 * by  Clandrie (2014/Nov/13)
 * mod GoToLoop
 *
 * forum.processing.org/two/discussion/8115/changing-color-of-piechart
 *
 * studio.processingtogether.com/sp/pad/export/ro.9cEo3JxuOM3wG/latest
 */
 
static final short[]  ANGLES = { // total = 360°
  100, 75, 50, 90, 45
};
 
static final color[] COLORS = {
  #FF0000, #008000, #0000FF, #FFFF00, #00FFFF
};
 
void setup() {
  size(512, 480, JAVA2D);
  ellipseMode(CENTER);
  smooth();
  noLoop();
  stroke(0);
  strokeWeight(2);
}
 
void draw() {
  background(0100, 0200, 0400, 0300);
  drawPieChart(ANGLES, COLORS, height*3 >> 2);
  fill(0350);
  ellipse(width>>1, height>>1, width/6, height/6);
}
 
void drawPieChart(short[] angles, color[] colors, int diam) {
  final int rad = diam>>1, cw = width>>1, ch = height>>1;
  int idx = angles.length;
  float angSum = 0;
 
  while (idx-- != 0) {
    float ang = radians(angles[idx]);
    float dx  = cw + rad*cos(angSum), dy = ch + rad*sin(angSum);
 
    fill(colors[idx]);
    arc(cw, ch, diam, diam, angSum, angSum += ang);
    line(cw, ch, dx, dy);
  }
}
AAAAAAAA