Created
May 14, 2012 18:22
-
-
Save foota/2695499 to your computer and use it in GitHub Desktop.
Map of convenience stores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String convData = "data.tsv.gz"; | |
String japanMap = "japan.svg"; | |
PShape mapShape; | |
int totalCount; | |
Place[] places; | |
int placeCount = 0; | |
final float minX = -0.19834; | |
final float maxX = 0.2425; | |
final float minY = -0.1875; | |
final float maxY = 0.1845; | |
PImage mapImage; | |
PFont font; | |
float offset_x = 0.0; | |
float offset_y = 0.0; | |
int center_x = 0; | |
int center_y = 0; | |
float zoom = 1.0; | |
int mx_start, my_start, my_pos; | |
String[] convName = { "Seven-Eleven", "LAWSON", "FamilyMart", "Circle K", "Sunkus", "Daily YAMAZAKI", | |
"MINISTOP", "am/pm", "POPLAR", "Three F", "COMMUNITY STORE", "Cocostore", "SHOP99", | |
"Seicomart", "SAVE ON" }; | |
color[] convColor = { #ff0000, #007fff, #00ff00, #ffff00, #ff00ff, #00ffff, | |
#7f0000, #0000ff, #007f00, #7f7f00, #7f007f, #007f7f, #7f7f7f, | |
#ff7f00, #7f00ff }; | |
boolean[] convIds = { true, true, false, false, false, false, false, false, false, false, false, false, false, false, false }; | |
int numConv = 15; | |
public void setup() { | |
mapShape = loadShape(japanMap); | |
smooth(); | |
loop(); | |
size(int(mapShape.width), int(mapShape.height), JAVA2D); | |
shapeMode(CORNER); | |
mapShape.disableStyle(); | |
font = loadFont("CourierNewPSMT-14.vlw"); | |
textMode(SCREEN); | |
textFont(font); | |
readData(); | |
} | |
public void draw() { | |
background(0); | |
noStroke(); | |
fill(32); | |
shape(mapShape, int(offset_x * zoom) + center_x, int(offset_y * zoom) + center_y); | |
for (int i = 0; i < placeCount; i++) places[i].draw(); | |
for (int i = 0; i < numConv; i++) { | |
fill(convColor[i]); | |
text(convName[i], 15, 15 * (i + 1)); | |
if (convIds[i]) text("*", 5, 15 * (i + 1)); | |
} | |
} | |
float TX(float x) { | |
float offset = width * (1.0 - zoom) * 0.5; | |
return map(x, minX, maxX, offset, width - offset); | |
} | |
float TY(float y) { | |
float offset = height * (1.0 - zoom) * 0.5; | |
return map(y, minY, maxY, height - offset, offset); | |
} | |
void mousePressed() { | |
mx_start = int(mouseX - offset_x * zoom); | |
my_start = int(mouseY - offset_y * zoom); | |
loop(); | |
for (int i = 0; i < numConv; i++) | |
if (mouseX < convName[i].length() * 8 + 15 && mouseY > 15 * i && mouseY < 15 * (i + 1)) | |
convIds[i] = !convIds[i]; | |
my_pos = mouseY; | |
} | |
void mouseReleased() { | |
noLoop(); | |
} | |
void mouseDragged() { | |
if (mouseButton == LEFT) { | |
offset_x = (mouseX - mx_start) / zoom; | |
offset_y = (mouseY - my_start) / zoom; | |
} else if (mouseButton == RIGHT) { | |
if (mouseY - my_pos > 4) { | |
float zoom_out = 9.8 / 10.0; | |
mapShape.scale(zoom_out); | |
zoom *= zoom_out; | |
center_x = int(width * (1.0 - zoom) * 0.5); | |
center_y = int(height * (1.0 - zoom) * 0.5); | |
my_pos = mouseY; | |
} else if (mouseY - my_pos < -4) { | |
float zoom_in = 10.0 / 9.8; | |
mapShape.scale(zoom_in); | |
zoom *= zoom_in; | |
center_x = int(width * (1.0 - zoom) * 0.5); | |
center_y = int(height * (1.0 - zoom) * 0.5); | |
my_pos = mouseY; | |
} | |
} | |
} | |
void readData() { | |
new Slurper(); | |
} | |
Place parsePlace(String line) { | |
String pieces[] = split(line, '\t'); | |
int id = int(pieces[0]); | |
String name = pieces[1]; | |
float x = float(pieces[2]); | |
float y = float(pieces[3]); | |
return new Place(id, name, x, y); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Place { | |
int id; | |
String name; | |
float x, y; | |
public Place(int id, String name, float x, float y) { | |
this.id = id; | |
this.name = name; | |
this.x = x; | |
this.y = y; | |
} | |
public void draw() { | |
if (convIds[this.id]) { | |
int xx = (int)TX(x) + int(offset_x * zoom); | |
int yy = (int)TY(y) + int(offset_y * zoom); | |
set(xx, yy, convColor[this.id]); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Slurper implements Runnable { | |
Slurper() { | |
Thread thread = new Thread(this); | |
thread.start(); | |
} | |
public void run() { | |
try { | |
BufferedReader reader = createReader(convData); | |
String line = reader.readLine(); | |
totalCount = int(line); | |
places = new Place[totalCount]; | |
while ((line = reader.readLine()) != null) { | |
places[placeCount] = parsePlace(line); | |
placeCount++; | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
noLoop(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def UTM(lat, lng): | |
lng0 = 35 | |
lat0_list = ((abs(lat - 129.0), 129.0, -3.0), | |
(abs(lat - 135.0), 135.0, 0.0), | |
(abs(lat - 141.0), 141.0, 3.0)) | |
lat0 = sorted(lat0_list)[0][1] | |
lat0_diff = sorted(lat0_list)[0][2] | |
y = (lng - lng0) / 180.0 * math.pi | |
x = math.log(math.tan(math.pi / 4.0 + (lat - lat0) / 180.0 * math.pi / 2.0)) + math.log(math.tan(math.pi / 4.0 + lat0_diff / 180.0 * math.pi / 2.0)) * 2.0 | |
return x, y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://handasse.blogspot.com/2009/12/blog-post.html
http://handasse.blogspot.com/2009/12/processing.html