/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.9IM3o0Uk3IA/rev.3
*
* authors:
* GoToLoop
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
/**
* 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);
}
}