Basics > Form > PieChart
- Mouse (tasto): diagramma a torta casuale.
- Applicazione Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
int NUMERO; int VALORI[]; float angoli[]; float xc, yc; float raggio1, raggio2; color colore; void setup() { size(500, 500); noStroke(); smooth(); ellipseMode(RADIUS); PFont font = loadFont("C16.vlw"); textFont(font); textAlign(CENTER); xc=width/2; yc=height/2; raggio1=0.42*width; raggio2=0.47*width; esegui(); noLoop(); } void mousePressed() { esegui(); redraw(); } void esegui() { NUMERO=(int)random(5, 10); VALORI=new int[NUMERO]; for(int i=0; i < NUMERO; i++) VALORI[i]=(int)random(5, 50); int totale=0; for(int i=0; i < NUMERO; i++) totale += VALORI[i]; float angolo=TWO_PI/totale; angoli=new float[NUMERO]; for(int i=0; i < NUMERO; i++) angoli[i] = angolo*VALORI[i]; } void draw() { background(255); float angolo=0; for (int i=0; i < NUMERO; i++) { colore=color(random(0, 128), random(0, 128), random(0, 128)); fill(colore); stroke(colore); arc(xc, yc, raggio1, raggio1, angolo, angolo+angoli[i]); text(VALORI[i], xc+raggio2*cos(angolo+angoli[i]/2), yc+raggio2*sin(angolo+angoli[i]/2)); angolo += angoli[i]; } } |