Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PFont f;
- float WIDTH = 1280;
- float HEIGHT = 720;
- float MARGIN = 50;
- float MIN_LONG = 22;
- float MAX_LONG = 50;
- float MIN_LAT = -128;
- float MAX_LAT = -67;
- String[] zips;
- int zipNb;
- float oldLong, oldLat, newLong, newLat;
- String firstDigits="01";
- color c = color(random(0,255),random(0,255),random(0,255));
- void setup(){
- size(1280, 720);
- frameRate(10000);
- strokeWeight(1);
- zips = loadStrings("zips.txt");
- zipNb = 1;
- background(255);
- f = createFont("Calibri", 42);
- textFont(f);
- }
- void draw(){
- //background(255);
- boolean connect = true;
- String[] zip = zips[zipNb].split("");
- String firstTwoDigits = zip[0]+zip[1];
- if(!firstTwoDigits.equals(firstDigits)){
- c = color(random(0,255),random(0,255),random(0,255));
- connect = false;
- firstDigits = firstTwoDigits;
- }
- connectZip(zipNb, connect);
- zipNb+=1;
- if(zipNb % 20 == 0){
- // Save frame every 20 frames
- //saveFrame("movie/######.png");
- }
- }
- void connectZip(int nb, boolean connect){
- if(nb>zips.length-1) exit();
- //println(zips[nb]);
- String[] zip = zips[nb].split("\t");
- fill(255);
- stroke(255);
- rect(25,0,150,50);
- noStroke();
- fill(0);
- newLong = Float.parseFloat(zip[1]);
- newLat = Float.parseFloat(zip[2]);
- //print(newLong + "," + newLat);
- if(connect){
- drawLine(oldLong, oldLat, newLong, newLat);
- double length = Math.sqrt( Math.pow(newLong-oldLong,2) + Math.pow(newLat-oldLat,2) );
- if(length > 10) println(zip);
- }else{
- drawLine(newLong, newLat, newLong, newLat);
- }
- oldLong = newLong;
- oldLat = newLat;
- }
- void drawLine(float long1, float lat1, float long2, float lat2){
- // Plot line on the graph
- if(long1<MIN_LONG || lat1<MIN_LAT) return;
- if(long1>MAX_LONG || lat1>MAX_LAT) return;
- Point startPoint = mapPoint(long1, lat1);
- Point endPoint = mapPoint(long2, lat2);
- stroke(c);
- line(startPoint.x, startPoint.y, endPoint.x, endPoint.y);
- }
- Point mapPoint(float longitude, float latitude){
- // Converts a longitude-latitude pair into A,Y coords on the canvas
- float spanX = (HEIGHT-MARGIN*2) / (MAX_LONG-MIN_LONG);
- float spanY = (WIDTH-MARGIN*2) / (MAX_LAT-MIN_LAT);
- float y = HEIGHT - (MARGIN + spanX * (longitude - MIN_LONG));
- float x = MARGIN + spanY * (latitude - MIN_LAT);
- return new Point(x, y);
- }
- class Point{
- public float x, y;
- Point(float x, float y){
- this.x = x;
- this.y = y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement