// the frequencies as collected during the in class survey String[] month; int[] numBirthdays; void setup() { // Read data from file, populate the data arrays String[] lines = loadStrings("birthdays.txt"); for (String s : lines) { println(s); } // create data arrays to store the data present in lines month = new String[lines.length]; numBirthdays = new int[lines.length]; for (int i = 0; i < lines.length; i++) { // split line into its pieces String[] pieces = split(lines[i], ","); month[i] = pieces[0]; numBirthdays[i] = int(pieces[1]); } println("There were " + numBirthdays.length + " entries."); for (int n : numBirthdays) { println(n); } // Sketch set up... size(800, 400); //size(displayWidth, displayHeight); smooth(); background(#D8D4D4); noLoop(); } // setup() void drawBarGraph(int[] data, String[] labels) { // set up plot variables float x = 0.05*width; float plotW = 0.9*width; float y = 0.80*height; float plotH = 0.75*height; float delta = plotW/numBirthdays.length; float w = delta/2; int lo = 0; int hi = max(numBirthdays); for (int i = 0; i < data.length; i++) { float h = map(data[i], lo, hi, 0, plotH); fill(#AA21B4); rect(x+i*delta, y-h, w, h); // Draw the labels below pushMatrix(); fill(0); translate(x+i*delta, y+20); rotate(radians(45)); text(labels[i], 0, 0); popMatrix(); } } // drawBarGraph() void draw() { // Draw a bar graph drawBarGraph(numBirthdays, month); } // draw()