ArrayList countryList; int mode = 1; PFont fontSmall; PFont fontBig; void setup() { size(800,600); smooth(); frameRate(30); colorMode(HSB, 100); fontSmall = loadFont("MyriadPro-SemiExt-14.vlw"); fontBig = loadFont("MyriadPro-SemiExt-48.vlw"); textFont(fontSmall, 10); parseData(); } void draw(){ background(95); for(int i = 0; i < countryList.size(); i++){ Countries country = countryList.get(i); country.display(mode); if(frameCount < 2){ country.verify(); } } textAlign(LEFT); textFont(fontSmall, 11); fill(30,50,65,100); text("Press 1 to compare AREA", 10, height-60); fill(50,50,65,100); text("Press 2 to compare POPULATION", 10, height-40); fill(70,65,65,100); text("Press 3 to compare POPULATION DENSITY", 10, height-20); headingDisplay(mode); } void parseData() { countryList = new ArrayList(); String[] lines = loadStrings("cia_factbook.csv"); for(int i = 0; i < lines.length; i++) { if(i>0){ String line = lines[i]; String chunks[] = line.split(","); String name = chunks[0].trim(); String population = chunks[1].trim(); String latitude = chunks[2].trim(); String longitude = chunks[3].trim(); String area = chunks[4].trim(); println(name); println(chunks[4]); countryList.add( new Countries( name, makeFloat(population), makeFloat(latitude), makeFloat(longitude), makeFloat(area) ) ); } } } float makeFloat(String input){ if(input.indexOf("E+") > -1){ String chunks[] = input.split("E+"); float decimal = float(chunks[0]); chunks[1] = chunks[1].substring(1); println(chunks); int exponent = int(chunks[1]); float output = decimal * pow(10, exponent); return output; } else { float output = float(input); return output; } } void keyPressed() { if (key == '1') { mode = 1; } if (key == '2') { mode = 2; } if (key == '3') { mode = 3; } } void headingDisplay(int mode){ textAlign(CENTER); textFont(fontBig, 18); fill(0); if(mode==1){ text("Global Comparison of Geographical Area", width/2 + width/8, height-20); } if(mode==2){ text("Global Comparison of Population", width/2 + width/8, height-20); } if(mode==3){ text("Global Comparison of Population Density", width/2 + width/8, height-20); } }