//DividedBar int[] data = {6, 14, 6, 14}; String[] labels = {"Spring", "Summer", "Fall", "Winter"}; int total; float[] perc = new float[data.length]; color[] colors = {color(255,165,0), color(255,255,0), color(20,220,50), color(135,165,235)}; //The sketch variables // The sketch variables float x, y, barL, barH; float startX, startY, stopX, stopY; void setup(){ size(500,500); background(255); smooth(); noLoop(); // process // compute the total population total = 0; for (int i=0; i < data.length; i++) { total += data[i]; } // compute percentages for (int i=0; i < data.length; i++) { perc[i] = float(data[i])/total; } // bar/sketch variables barL = width-100; // length of the bar to be divided barH = 50; x = 50; y = (height-barH)/2.0; // h = 240; // s = 0; // b = 87; }//setup void draw(){ // colorMode(HSB, 100); startX = x; startY = y; stopX = startX; stopY = startY; for (int i=0; i < perc.length; i++) { // set up pie parameters for ith bar startX = stopX; startY = stopY; stopX = startX + perc[i]*barL; // draw the bar noStroke(); fill(colors[i]); //fill(h, 100/7*i, b); rect(startX, startY, stopX-startX, barH); // legend stroke(0); fill(0); textSize(12); if (i%2 == 0) { line(startX, startY+barH, startX, startY+barH+10); text(labels[i], startX, startY+barH+10+12); } else { line(startX, startY, startX, startY-10); text(labels[i], startX, startY-10); } } // draw title fill(0); textSize(24); rectMode(CENTER); text("Births by Day of Week", 105, 50); }