//Original Concept and Code by Noah King //for Expression Frameworks course //ITP Fall 2010 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); } } class Countries{ String mName; float mPopulation; float mLongitude; float mLatitude; float mArea; float multi; Countries(String name, float population, float latitude, float longitude, float area){ float longMultiplier = width/360; float latMultiplier = height/150; mName = name; mPopulation = population; mArea = area; mLongitude = (longitude + 180) * longMultiplier; mLatitude = (latitude * -1 + 90) * latMultiplier; } void update(){ } void verify(){ println("name: " + mName + ", pop: " + mPopulation + ", area: " + mArea + ", coords(" + mLongitude + ", " + mLatitude + ")"); } void display(int mode){ if(mode==1){ multi = 50000; fill(30,50,65,25); stroke(30,50,65,80); ellipse(mLongitude, mLatitude, mArea/multi + 1, mArea/multi + 1); textAlign(CENTER); fill(100,0,0, mArea/multi/2 + 20); textFont(fontBig, mArea/multi/14 + 7); text(mName, mLongitude, mLatitude); } if(mode==2){ multi = 3000000; fill(50,50,65,25); stroke(50,50,65,70); ellipse(mLongitude, mLatitude, mPopulation/multi + 1, mPopulation/multi + 1); textAlign(CENTER); fill(100,0,0, mPopulation/multi/2 + 20); textFont(fontBig, mPopulation/multi/20 + 7); text(mName, mLongitude, mLatitude); } if(mode==3){ multi = 2.5; fill(70,50,65,5); stroke(70,50,65,25); ellipse(mLongitude, mLatitude, mPopulation/mArea/multi + 1, mPopulation/mArea/multi + 1); textAlign(CENTER); fill(100,0,0, mPopulation/mArea/multi/3 + 20); textFont(fontBig, mPopulation/mArea/multi/16 + 7); text(mName, mLongitude, mLatitude); } } }