//-----set up array lists for each candidate & position ArrayList forObama = new ArrayList(); ArrayList againstObama = new ArrayList(); ArrayList forRomney = new ArrayList(); ArrayList againstRomney = new ArrayList(); void setup() { size(1280, 720); smooth(); //load data and establish positions, colors, sizes of ellipses loadData(); position(); //for debugging println("For Obama: " + forObama.size()); println("Against Obama: " + againstObama.size()); println("For Romney: " + forRomney.size()); println("Against Romney: " + againstRomney.size()); } void draw() { background(255); stroke(0); line(width/2,0,width/2,height); line(0,height/2,width,height/2); //render all ellipses to the screen for (Expenses ex:forObama) { ex.render(); } for (Expenses ex:againstObama) { ex.render(); } for (Expenses ex:forRomney) { ex.render(); } for (Expenses ex:againstRomney) { ex.render(); } } //-----load & parse the data void loadData() { String [] rows = loadStrings("expenses.csv"); //establish strings of phrases to look for String obama = "OBAMA BARACK, Obama Barack, Obama Barak, Barak Obama, Barack Obama"; String romney = "ROMNEY MITT, Romney Mitt, MITT ROMNEY, Mitt Romney"; String support = "Support"; for (int i = 1; i < rows.length; i++) { Expenses ex = new Expenses(); //create new expenses object for each row ex.fromCSV(rows[i].split(",")); //load CSV within object and split it //println(ex.candidate); //separate the "obama" objects from everything else if (obama.indexOf(ex.candidate) != -1) { //println("got an Obama!"); //separate the "support" objects from the "oppose" objects if (support.indexOf(ex.position) != -1) { forObama.add(ex); //add to the support array list //println("added!"); } else { againstObama.add(ex); //add to the oppose array list } } //separate "romney" objects from everything else if (romney.indexOf(ex.candidate) != -1) { //println("ewwwww!"); //separate "support" objects from everything else if (support.indexOf(ex.position) != -1) { forRomney.add(ex); //add to support array list } else { againstRomney.add(ex); //add to oppose array list } } } } //-----establish positions, colors, sizes of ellipses void position() { for (int i = 0; i < forObama.size(); i++) { Expenses e = forObama.get(i); //position at top left of screen e.pos.x = random(10, width/2-10); e.pos.y = random(10, height/2-10); //color the ellipses blue e.collins = color(0, 0, 255); //map area of ellipses to amount of expense e.d = map(sqrt(e.amount),sqrt(0),sqrt(18000000),1,20); } for (int i = 0; i < againstObama.size(); i++) { Expenses e = againstObama.get(i); //position at bottom left of screen e.pos.x = random(10, width/2-10); e.pos.y = random(height/2+10, height-10); //color ellipses blue e.collins = color(0, 0, 255); //map area of ellipses to amount of donation e.d = map(sqrt(e.amount),sqrt(0),sqrt(18000000),1,20); } for (int i = 0; i < forRomney.size(); i++) { Expenses e = forRomney.get(i); //positon at top right of screen e.pos.x = random(width/2+10, width-10); e.pos.y = random(10, height/2-10); //color ellipses red e.collins = color(255, 0, 0); //map area of ellipses to amount of donation e.d = map(sqrt(e.amount),sqrt(0),sqrt(18000000),1,20); } for (int i = 0; i < againstRomney.size(); i++) { Expenses e = againstRomney.get(i); //position at bottom right of screen e.pos.x = random(width/2+10, width-10); e.pos.y = random(height/2+10, height-10); //color ellipses red e.collins = color(255, 0, 0); //map area of ellipses to amount of donation e.d = map(sqrt(e.amount),sqrt(0),sqrt(18000000),1,20); } } class Expenses { String candidate; //candidate name float amount; //amount of donation String position; //support or oppose PVector pos = new PVector(); //position of ellipse float d; //diamater of ellipse color collins; //color of ellipse //-----define variables for desired pieces of the data void fromCSV(String [] input) { candidate = input[1]; amount = float(input[9]); //convert string to float position = input[12]; } //-----render data to screen void render() { pushMatrix(); translate(pos.x, pos.y); noStroke(); fill(collins); ellipse(0,0,d,d); popMatrix(); } }