Skip to content

Instantly share code, notes, and snippets.

@jacopocolo
Last active November 4, 2017 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacopocolo/69663014d276b4dfa56a4493b4315620 to your computer and use it in GitHub Desktop.
Save jacopocolo/69663014d276b4dfa56a4493b4315620 to your computer and use it in GitHub Desktop.
var angles = [ 30, 10, 45, 35, 60, 38, 75, 67 ];
function setup() {
createCanvas(400, 300);
noStroke();
}
function draw() {
background(0);
pieChart(250, angles);
}
function pieChart(diameter, data) {
var lastAngle = 0;
for (var i = 0; i < data.length; i++) {
var gray = map(i, 0, data.length, 100, 255);
fill(gray);
arc(width/2, height/2, diameter, diameter, lastAngle, lastAngle+radians(angles[i]));
lastAngle += radians(angles[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment