//Original Concept and Code by Noah King //for Expression Frameworks course //ITP Fall 2010 PFont font1; Countries [] country = new Countries[194]; void setup() { size(800,600); smooth(); frameRate(30); colorMode(RGB, 100); font1 = loadFont("MyriadPro-SemiExt-12.vlw"); textFont(font1,12); parseData(); } void draw(){ background(70); for(int i = 1; i < 194; i++){ if(country[i].mPopulation > 0.0) { country[i].update(); stroke(30,30,50,20); if(i > 2){ line(country[i].mPos.x, country[i].mPos.y, country[i-1].mPos.x, country[i-1].mPos.y); } else { line(country[i].mPos.x, country[i].mPos.y, country[193].mPos.x, country[193].mPos.y); } country[i].display(); } } } void parseData() { String[] lines = loadStrings("world_population.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(); country[i] = new Countries(name, float(population)); } } } class Countries{ String mName; float mPopulation; float mOffset; PVector mPos = new PVector(0.0, 0.0); PVector mVel = new PVector(0.0, 0.0); PVector mAcl = new PVector(0.0, 0.0); float mAngle; Countries(String name, float population){ mName = name; mPopulation = population; mPopulation /= 1300000; mPopulation *= width/2; mOffset = mPopulation/2; mPos.x = random(mOffset, width-mOffset); mPos.y = random(mOffset, height-mOffset); mVel.x = random(2.0)/ sqrt(mOffset/5); mVel.y = random(2.0)/ sqrt(mOffset/5); if(mVel.x > 2.0 ){ mVel.x = random(1.5, 2.5);} if(mVel.y > 2.0 ){ mVel.y = random(1.5, 2.5);} //mAcl.y = mOffset/500; } void update(){ if(mPos.x > width - mOffset || mPos.x < 0 + mOffset){ mVel.x *= -1; } if(mPos.y > height - mOffset || mPos.y < 0 + mOffset){ mVel.y *= -1; //mPos.y = height - mOffset; } mVel.add(mAcl); mPos.add(mVel); } void display(){ fill(100,15); stroke(100,50); ellipse(mPos.x, mPos.y, mPopulation, mPopulation); fill(100, 0, 0, mOffset*2 + 20); textAlign(CENTER); text(mName, mPos.x, mPos.y); } }