- String[] getSector(){
- String[] sectors ={"General public services", "Public order and safety",
- "Education", "Health", "Social Security and welfare",
- "Housing and community amenities", "Recreation and culture", "Fuel and energy",
- "Agriculture, forestry, fishing and hunting",
- "Mining and mineral resources other than fuels", "Transport and communications",
- "Other economic affairs", "Other purposes"};
- return sectors;
- }
- int[] getBudget() {
- int[] budgets = {408, 1752, 4364, 5618, 1437, 1275, 421, 74, 213, 73, 1215, 390, 755};
- return budgets;
- }
- int sumArray(int[] values) {
- int sum = 0;
- for (int i =0; i< values.length; i++){
- sum= sum+values[i];
- }
- return sum;
- }
- void tablePrinter(int[] colors){
- textSize(height/40);
- int margin = 20;
- String[] sectors = getSector();
- int[] budgets = getBudget();
- int sum = sumArray(budgets);
- for (int i =0; i< sectors.length; i++){
- fill(colors[i], colors[1+i], colors[2+i]);
- rect(margin/2, 0 + i*(height -6*margin)/sectors.length, margin, margin);
- text(sectors[i], 2*margin, margin + i*(height -6*margin)/sectors.length);
- text(budgets[i], 600, margin + i*(height -6*margin)/budgets.length);
- }
- fill(0);
- text("sum", margin, height -4*margin);
- text(sum, 600, height -4*margin);
- line(550,0, 550, height-margin);
- line(0,height-6*margin, width/2 -margin, height -6*margin);
- }
- void drawPie(int[]colors){
- stroke(0);
- textSize(3);
- strokeWeight(3);
- int margin = 20;
- int tab = 800;
- String[] sectors = getSector();
- int[] budgets = getBudget();
- int sum = sumArray(budgets);
- float cumulatedAngle = 0;
- for (int i=0; i < budgets.length; i++){
- fill(colors[i], colors[i+1], colors[i+2]);
- arc(3* width/4, height/2, width/2 - 2*margin, width/2 -2*margin, cumulatedAngle, cumulatedAngle+TWO_PI*budgets[i]/sum, PIE);
- cumulatedAngle = cumulatedAngle+TWO_PI*budgets[i]/sum;
- }
- }
- void setup(){
- size(1600,1000);
- background(255);
- int[] colors = new int[39];
- for (int i=0; i<39; i++){
- colors[i]= int(random(0,255));
- }
- tablePrinter(colors);
- drawPie(colors);
- }