How to make (almost) anything

Tim Fallon - 2014

Week 13 - Interface programming

This week our assignment was to dive into the wide world of GUI programming. There are a lot of options, from more GUI based things like QT or Tk, or basic compositing packages like OpenGL, SDL, Pygame. I decided to go with Pygame, as I am familiar with Python, and having the flexibility to composite from the ground up is a nice feature. One idea I had for a final project was a live MBTA map that could go on the wall of my apartment. Underneath would be LEDs, and I could raster the positions of trains, buses, etc, onto this LED matrix. Towards this goal, I decided to use this week to play around with the MBTA realtime data API and draw it on a map as a proof of principle.


  • Used Pygame
  • Interfaced with MBTA realtime data
  • Drew it on an openstreetmap map.

  • Parsing MBTA realtime data with the magic of python

    First, I used data from the MBTA realtime feed: see the MBTA realtime data portal for more info. Querying data from it couldn't be easier. As I show above, you give a HTTP request, and the server responds with a JSON object. Since all this has well supported libraries, in only a few lines you have python dictionaries and lists containing all the data. The MBTA provides latitude, longitude, heading, as well as when the timestamp for when those data were collected, so you can make a pretty reasonable interactive map.

    Openstreet map

    With the location data from the MBTA realtime feed, I then needed something to plot it on. I turned to OpenStreetMap which is a freely available open-sourced mapping community. They let you define a X-Y area defined by latitude and longitude and the download PNGs of that area directly. This was exactly what I needed just to put dots of the trains on a map. An aside on mapping however: You may have heard that the world is in fact a sphere and not a 2D plane. Worse than that, the world is actually an oblate spheroid and not a sphere. This means that any representation of the Earth as a 2D surface (such as a map) is necessarily wrong. While I think my approach is reasonable for a small area, this starts to breakdown with anything large. For more details, check out WGS 84, which is the "real" coordinate system for the Earth. This seems to me to be a non-trivial problem, and I haven't found any good libraries to deal with it.

    Traces and exterior PNGs overlayed.
    The final program

    The final program then brings the realtime data together with the open street map to draw some spheres where the trains should be. I also add a line to indicate the heading of the train. Todo: Try and design a large format LED matrix, which can be a bit non-trivial.