String[] suburbsData; HashMap suburbs = new HashMap(); HashMap suburbChild = new HashMap(); int postcode; float longitude; float latitude; String suburb; String state; float x; float y; String[] lineData; String keyFilter = ""; float[] longitudes; float[] latitudes; boolean filtered = false; color idleColour = color(90, 80, 70); color overColour = color(255, 230, 40); color backgroundColour = color(30); float long_min; float long_max; float lat_min; float lat_max; PFont font; void setup() { size(800, 600); background(backgroundColour); suburbsData = loadStrings("data.txt"); longitudes = new float[suburbsData.length]; latitudes = new float[suburbsData.length]; for(int i = 0 ; i < suburbsData.length ; i++) { lineData = suburbsData[i].split("\t"); longitude = float(lineData[3]); latitude = float(lineData[4]); longitudes[i] = longitude; latitudes[i] = latitude; } long_min = min(longitudes); long_max = max(longitudes); lat_min = min(latitudes); lat_max = max(latitudes); x = new Float(0.0); y = new Float(0.0); for(int i = 0 ; i < suburbsData.length ; i++) { lineData = suburbsData[i].split("\t"); suburb = lineData[1]; state = lineData[2]; longitude = float(lineData[3]); latitude = float(lineData[4]); postcode = int(lineData[5]); suburbChild = new HashMap(); x = norm(latitude, lat_min, lat_max); y = norm(longitude, long_min, long_max); y = 1.0-y; suburbChild.put("postcode",new Integer(postcode)); suburbChild.put("y",y); suburbChild.put("x",x); suburbChild.put("suburb", suburb); suburbChild.put("state", state); suburbs.put(suburb, suburbChild); } smooth(); noStroke(); font = loadFont("HelveticaNeue-Light-24.vlw"); textFont(font); noLoop(); } Iterator it; HashMap filteredSuburbs; void draw() { background(backgroundColour); filteredSuburbs = new HashMap(); it = suburbs.entrySet().iterator(); while(it.hasNext()) { Map.Entry me = (Map.Entry)it.next(); HashMap values = (HashMap)me.getValue(); suburb = (String)(values.get("suburb")); state = (String)(values.get("state")); postcode = (Integer)(values.get("postcode")); x = (Float)(values.get("x")); y = (Float)(values.get("y")); stroke(idleColour); keyFilter = keyFilter.toLowerCase(); if(filtered && (str(postcode).startsWith(keyFilter) || suburb.toLowerCase().startsWith(keyFilter))) { filteredSuburbs.put(suburb, values); } else { point(x*width, height*0.1 + y*height*0.8); } } float y_pos = 0.0; boolean firstDrawn = false; it = filteredSuburbs.entrySet().iterator(); while(it.hasNext()) { Map.Entry me = (Map.Entry)it.next(); HashMap values = (HashMap)me.getValue(); suburb = (String)(values.get("suburb")); state = (String)(values.get("state")); postcode = (Integer)(values.get("postcode")); x = (Float)(values.get("x")); y = (Float)(values.get("y")); stroke(overColour); //ellipse(x*width, height*0.1 + y*height*0.8, 3, 3); point(x*width, height*0.1 + y*height*0.8); if(filtered && (keyFilter.equalsIgnoreCase(str(postcode)) || keyFilter.equalsIgnoreCase(suburb))) { if(!firstDrawn) { firstDrawn = true; y_pos = y*height*0.8; } y_pos += 15; textAlign(LEFT); if(x > 0.9) textAlign(RIGHT); textFont(font, 12); println(str(postcode) + " " + toProperCase(suburb) + ", " + state); text(str(postcode) + " " + toProperCase(suburb) + ", " + state, x*width, height*0.1 + y_pos); } } textAlign(LEFT); textFont(font, 24); fill(idleColour); if(filtered) fill(overColour); text("> " + keyFilter, 15, 30); if(!filtered) text(suburbs.size() + " suburbs in total.", 15, 60); else text(filteredSuburbs.size() + " found.", 15, 60); } String toProperCase(String name) { String[] names = name.split(" "); String theName = ""; for(int i = 0 ; i < names.length ; i++) { theName += names[i].substring(0, 1).toUpperCase() + names[i].substring(1).toLowerCase(); theName += " "; } return theName; } void keyPressed() { if(key == BACKSPACE || key == DELETE) { if(keyFilter.length() > 0) { keyFilter = keyFilter.substring(0, keyFilter.length() - 1); if(keyFilter.length() == 0) { filtered = false; } } } else if(key != CODED) { filtered = true; keyFilter += str(key); } redraw(); }