Pie Chart Wedge Colors
in
Programming Questions
•
2 years ago
I want a pie chart with two values and I've started with a modified version of the pie chart example on processing.org
When I used the online processing.js editor, the color differentiation showed up, except when the values are 50/50 and they become the same color.
However, when I place this code in the standard processing editor on my computer, I get a circle of a solid color.
Is it possible to give each wedge a defined color? That would be easiest. But looking from how it's drawn I don't see how that can be done.
Here is the code I'm using:
size(200, 200);
background(255);
smooth();
noStroke();
int players = 16;
int humans = 8;
int diameter = 150;
int[] angs = {humans/players*100, 0, 0, 0, 100-humans/players*100};
float lastAng = 0;
for (int i = 0; i < angs.length; i++){
fill(angs[i] * 3.0);
arc(width/2, height/2, diameter, diameter, lastAng, lastAng+radians(angs[i]*3.6));
lastAng += radians(angs[i]*3.6);
}
1