// Drawing a Pie Chart
void setup() {
   size(600, 600);
   background(255);
   noLoop();
} // setup()
void draw() {
   // The data
   int humanities = 6;
   int socSciences = 2;
   int sciences = 11;
   int undecided = 1;
   int total = humanities + socSciences + sciences + undecided;
   
   // Compute percentages
   float pHumanities = float(humanities)/total;
   float pSocSciences = float(socSciences)/total;
   float pSciences = float(sciences)/total;
   float pUndecided = float(undecided)/total;
   
   println("%Hum = " + pHumanities);
   println("%Soc = " + pSocSciences);
   println("%Sci = " + pSciences);
   println("%Und = " + pUndecided);
   
   // Draw the pie chart
   float x = width/2, y = height/2, sz = height/2;
   float startAngle = 0, stopAngle;
   float lx = 20, ly = height/2, lsz = 20;
   
   // Draw the pie for humanities
   fill(219, 62, 255);
   stopAngle = 2*PI*pHumanities;
   arc(x, y, sz, sz, startAngle, stopAngle);
   
   // Legend
   square(lx, ly, lsz);
   fill(0);
   text("Humanities", lx + lsz+ 5, ly+lsz);
   
   // Draw the pie for Social Sciences
   fill(6, 183, 128);
   startAngle = stopAngle;
   stopAngle = startAngle + 2*PI*pSocSciences;
   arc(x, y, sz, sz, startAngle, stopAngle);
   
   // Legend
   ly = ly + lsz+20;
   square(lx, ly, lsz);
   fill(0);
   text("Social Sciences", lx + lsz+ 5, ly+lsz);
   
   // Draw the pie for sciences
   fill(252, 190, 74);
   startAngle = stopAngle;
   stopAngle = startAngle + 2*PI*pSciences;
   arc(x, y, sz, sz, startAngle, stopAngle);
   
   // Legend
   ly = ly + lsz+20;
   square(lx, ly, lsz);
   fill(0);
   text("Sciences", lx + lsz+ 5, ly+lsz);
   
   // Finally, undecided
   fill(255, 88, 88);
   startAngle = stopAngle;
   stopAngle = startAngle + 2*PI*pUndecided;
   arc(x, y, sz, sz, startAngle, stopAngle); 
   
   // Title
   fill(0);
   textSize(18);
   text("2022 Declared UG Majors in Sciences at Bryn Mawr College", 80, 100);
   text("Source: Bryn Mawr Factbook (3/16/2022)", 120, 120);
   
   // Legend
   textSize(12);
   ly = ly + lsz+20;
   square(lx, ly, lsz);
   fill(0);
   text("Undecided", lx + lsz+ 5, ly+lsz);
   
   // Signature
   text("Created by Deepak Kumar", 400, 450);
   
} // draw()