// Flight data Parser by Aaron Koblin 2005. // // (not so clean and) simple. import processing.opengl.*; int stagex = 640; //stage width int stagey = 480; //steage height int waitLength = 110; PImage fade; PFont font; boolean isLoaded = false; int pacer = 0; String lines[]; String[] theText = new String[10]; int days,hours, mins; int count = 0; void setup(){ framerate(30); background(255); size(720, 480); fade = loadImage("blank.jpg"); tint(0,0,0,255); image(fade, 0, 0, stagex, stagey); stroke(255,255,255,255); font = loadFont("BankGothicBT-Medium-18.vlw"); textFont(font, 14); textMode(SCREEN); textAlign(RIGHT); days = 19; hours = 21; mins = 58; theText[0]="particle "; // MEL scripts are fun and simple! (this is my excuse for poor programming practice) theText[1]="particle "; theText[2]="particle "; theText[3]="particle "; theText[4]="particle "; theText[5]="particle "; theText[6]="particle "; theText[7]="particle "; theText[8]="particle "; theText[9]="particle "; loadIt(); } void loadIt(){ count++; String theMins = "00" ,theHours="00"; if (mins < 10){ theMins = "0" + str(mins); } else theMins = str(mins); if (hours <10){ theHours = "0" + hours; } else theHours = str(hours); lines = loadMyStrings("http://localhost/faa/thefile"+ str(days) + theHours + theMins); int c = 1; while (lines[c].length() > 38){ float longitude = float(lines[c].substring(0,10)); float latitude = float(lines[c].substring(10,20)); String altitude = lines[c].substring(30,40); String type = lines[c].substring(40,50); if((altitude.substring(0,1).equals("?") || altitude.substring(0,1).equals(""))){ altitude = "0"; } altitude = str(float(altitude) / 20.0); c++; int opac = 255; if ((!altitude.equals("0.0"))&&(!altitude.equals("NaN"))){ int which = 0; stroke(255,255,255, opac); if(type.equals("T3")){ which = 1; stroke(10,255,10, opac); } else if(type.equals("L4")){ which = 2; stroke(255,10,10, opac); } else if(type.equals("B52")){ which = 3; stroke(10,10,255, opac); } else if(type.equals("?4")){ which = 4; stroke(10,150,255, opac); } else if(type.equals("5")){ which = 5; stroke(255,150,10, opac); } else if(type.equals("63c")){ which = 6; stroke(150,150,150, opac); } else if(type.equals("4f5")){ which = 7; stroke(250,250,0, opac); } else if(type.equals("43")){ which = 8; stroke(0,250,250, opac); } else if(type.equals("fr3")){ which = 9; stroke(200,100,70, opac); } strokeWeight(2); point(740-(longitude)*3.9, 480-(latitude)*6.9); theText[which] += "-jbp " + str((longitude*3.9)/10) +" " +str((latitude*6.9)/10)+" "+ altitude + "\n"; } } theText[0]+=";"; theText[1]+=";"; theText[2]+=";"; theText[3]+=";"; theText[4]+=";"; theText[5]+=";"; theText[6]+=";"; theText[7]+=";"; theText[8]+=";"; theText[9]+=";"; fill(0,0,0,255); noStroke(); fill(255,255,255,190); String thePlanes = str(c); stroke(230,230,230,190); String theTime = days + "-" + theHours +":"+theMins; // saveStrings("Frame"+count+".mel", theText); saveFrame("frame_"+count+".TGA"); println(count); } void draw(){ fadeit(); mins += 3; if (mins > 59){ mins = mins - 60; hours++; } if(hours>23){ hours = 0; days++; } theText[0]="particle "; theText[1]="particle "; theText[2]="particle "; theText[3]="particle "; theText[4]="particle "; theText[5]="particle "; theText[6]="particle "; theText[7]="particle "; theText[8]="particle "; theText[9]="particle "; loadIt(); } void fadeit(){ background(0,0,0); tint(255,255,255,15); image(fade, 0, 0, stagex, stagey); } //------------------- processing code added for enhanced error handling (not necessary at all)-------- static public String[] loadMyStrings(File file) { InputStream is = openStream(file); if (is != null) return loadStrings(is); return null; } public String[] loadMyStrings(String filename) { InputStream is = openStream(filename); if (is != null) return loadStrings(is); die("Couldn't open " + filename); return null; } static public String[] loadMyStrings(InputStream input) { try { BufferedReader reader = new BufferedReader(new InputStreamReader(input)); String[] lines = new String[100]; int lineCount = 0; String line = null; while ((line = reader.readLine()) != null) { if (lineCount == lines.length) { String temp[] = new String[lineCount << 1]; System.arraycopy(lines, 0, temp, 0, lineCount); lines = temp; } lines[lineCount++] = line; } reader.close(); if (lineCount == lines.length) { return lines; } // resize array to appropraite amount for these lines String output[] = new String[lineCount]; System.arraycopy(lines, 0, output, 0, lineCount); return output; } catch (IOException e) { // loadIt(); //return null; } return null; } public InputStream openStream(String filename) { InputStream stream = null; try { URL url = new URL(filename); stream = url.openStream(); return stream; } catch (MalformedURLException e) { // not a url, that's fine } catch (IOException e) { throw new RuntimeException("Error downloading from URL " + filename); // loadIt(); // println(count); //printlin ("Boooooyahkasha!"); } if (!online) { try { String location = folder + File.separator + "data"; File file = new File(location, filename); try { String path = file.getCanonicalPath(); String filenameActual = new File(path).getName(); //System.out.println(filename + " " + filenameActual); if (!filenameActual.equals(filename)) { throw new RuntimeException("This file is named " + filenameActual + " not " + filename + "."); //System.err.println("This image file is named " + // filenameActual + " not " + filename + "."); //System.err.println("Use loadImage(\"" + // filenameActual + "\") instead."); //return null; //System.out.println("found the wrong case"); //throw new RuntimeException("wrong case"); } } catch (Exception e) { } // ioex or security stream = new FileInputStream(file); if (stream != null) return stream; } catch (Exception e) { } // ioex or security } try { stream = getClass().getResourceAsStream(filename); if (stream != null) return stream; stream = getClass().getResourceAsStream("data/" + filename); if (stream != null) return stream; try { try { File file = new File(folder, filename); stream = new FileInputStream(file); if (stream != null) return stream; } catch (Exception e) { } // ignored try { stream = new FileInputStream(new File("data", filename)); if (stream != null) return stream; } catch (IOException e2) { } try { stream = new FileInputStream(filename); if (stream != null) return stream; } catch (IOException e1) { } } catch (SecurityException se) { } // online, whups if (stream == null) { //loadIt(); // throw new IOException("openStream() could not open " + filename); } } catch (Exception e) { die(e.getMessage(), e); } return null; // #$(*@ compiler } public void die(String what) { System.err.println("i'm dead.. " + what); loadIt(); // stop(); // throw new RuntimeException(what); /* if (online) { System.err.println("i'm dead.. " + what); } else { System.err.println(what); System.exit(1); } */ } /** * Same as above but with an exception. Also needs work. */ public void die(String what, Exception e) { if (e != null) e.printStackTrace(); die(what); }