วันพุธที่ 7 สิงหาคม พ.ศ. 2556

Array : Hard

Question... (Pie chart)Write a class that displays a pie chart of the data that is passed to its method as an array.
                เขียนโค้ดแสดงแผนภูมิวงกลมโดยการใช้ array

Answer...
                 void setup(){
                     size(300,300);
                     noStroke();
                     noLoop();
                }
              
                int[] angles={20,25,45,45,45,90,60,30};
                int[] cB={#FF0509,#FF05B9,#7D05FF,#056FFF,#00FFF9,#03FF00,#F6FF00,#F7B407};
                float start = 0;
                int i = 0;
                float diameter=200;

              void piechart(){  
                  while( i < angles.length){
                      fill(cB[i]);
                      arc(width/2, height/2, diameter, diameter, start, start+radians(angles[i]));
                      start+= radians(angles[i]);
                      i=i+1;
                  }
              }

              void draw(){
                  background(0);
                  piechart();
              }

             การแสดงผล:


.
source : Java for students
Douglas Bell and Mike Parr. -- 2nd ed. page 253
ISBN : 0-13010922-3

ไม่มีความคิดเห็น:

แสดงความคิดเห็น