Skip to content

Instantly share code, notes, and snippets.

@willbailey
Created April 3, 2010 16:28
Show Gist options
  • Save willbailey/354651 to your computer and use it in GitHub Desktop.
Save willbailey/354651 to your computer and use it in GitHub Desktop.
PShape bigMap;
PShape districtShape;
//PFont f;
import de.bezier.data.*;
XlsReader reader;
void setup() {
//basics
size(1000,800);
shapeMode(CENTER);
noStroke();
smooth();
//map import
bigMap = loadShape("map.svg");
bigMap.disableStyle();
fill(0);
shape(bigMap,500,400);
bigMap.disableStyle();
fill(255);
////////////////
// tax import //
reader = new XlsReader( this, "incometax.xls" );
reader.firstRow();
while ( reader.hasMoreRows() ) {
reader.nextRow();
String stateCode = reader.getString();
// exit loop once we reach the end of the values
if ( stateCode.indexOf(":") != -1 ) break;
reader.nextCell();
int districtNum = reader.getInt();
String districtCode = str(districtNum);
if (districtNum == 0) {
districtCode = "At-Large";
}
//concatenate district name
String districtID = stateCode + " " + districtCode;
reader.nextCell();
int taxBase = reader.getInt();
//convert tax to rgb value
int taxColor = taxBase / 130;
if (taxColor < 1) {
taxColor = 1;
}
colorDistrict(districtID, taxColor);
}
}
void colorDistrict(String districtID, int taxColor) {
//find object on map
try {
districtShape = bigMap.getChild(districtID);
districtShape.disableStyle();
fill(taxColor,taxColor,255);
shape(districtShape,500,400);
} catch (Exception e) {
println("could not find district in map: " + districtID);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment