// Data from line#1
int N;
float minX, maxX, minY, maxY;
Place[] places;
// Sketch variables
float mapX1, mapY1, mapX2, mapY2;
void setup() {
// Place p = new Place("19010", "Bryn Mawr", "PA", 40.44, 50.55);
//println(p);
// Read the data from a data file
readData();
println("N = " + N);
println("Min X = " + minX + ", Max X = " + maxX);
println("Min Y = " + minY + ", Max Y = " + maxY);
println("Read " + places.length + " zip codes.");
// Print the first ten place objects
for (int i = 0; i < 10; i++) {
println(places[i]);
}
// Draw the places as points
size(1600, 1000);
//size(displayWidth, displayHeight);
mapX1 = 30;
mapY1 = 20;
mapX2 = width - mapX1;
mapY2 = height - mapY1;
} // setup()
void draw() {
background(50);
for (Place p : places) {
p.display();
}
} // draw()
void readData() {
// Reads data from a data file
String[] lines = loadStrings("zips.txt");
// Neeeds to parse line#1
String[] firstLine = split(lines[0], " ");
String[] values = split(firstLine[1], ",");
N = int(values[0]);
minX = float(values[1]);
maxX = float(values[2]);
minY = float(values[3]);
maxY = float(values[4]);
// Needs to read the remainder of the place data
// First, create the data array
places = new Place[lines.length-1];
// Next, populate with all place objects read from file
for (int i = 1; i < lines.length; i++) {
// Extract and create an ith place object
String[] pieces = split(lines[i], "\t");
String zip = pieces[0];
float lat = float(pieces[1]);
float lon = float(pieces[2]);
String[] townState = split(pieces[3], ", ");
String town = townState[0];
String state = townState[1];
places[i-1] = new Place(zip, town, state, lat, lon);
}
} // readData()