import processing.xml.*;
//xml element to store and load yahoo pipes information
XMLElement pipes;
String pipeURL = new String("http://pipes.yahoo.com/pipes/pipe.run?_id=a135e8a8730f782fb817d792298562a4&_render=rss"); // location of yahoo pipes XML file or rss feed
void setup(){
size(360,180); // this size directly relates to longatude and latitude
smooth(); // turn smoothing on
background(255); // clear the window
pipes = new XMLElement(this, pipeURL);// make a new XML object for loading a XML file
initPipes(); // instilize pipes
}
//go through yahoo rss feed and collect all of it's data
void initPipes(){
XMLElement pipe;
XMLElement item;
XMLElement data;
//Strings used for matching speific daa in the incomming XML file..
String matchLat = "geo:lat";
String matchLong = "geo:long";
String matchTitle = "title";
// position and size of our earthquaes
float longX = 0;
float latY = 0;
float magnitude = 0;
//go through each item in the Yahoo Pipes XML file
//all information is stored in a item data structure with information about the XML file also being returned as an item.
/*
*/
for(int i = 0; i < pipes.getChild(0).getChildCount();i++){
item = pipes.getChild(0).getChild(i); // item will hold one item from the XML file
for(int e = 0; e < item.getChildCount();e++){ // go through each child item in the item //title ge:lat etc
data = item.getChild(e); // data is stored as a item in yahoo pipes and not a attribute, if we are at the correct item collect it's information
if(matchTitle.equals(data.getName()) == true)
magnitude = float(data.getContent());
if(matchLat.equals(data.getName()) == true)
latY = float(data.getContent());
if(matchLong.equals(data.getName()) == true)
longX = float(data.getContent());
}
if(longX != 0 & latY != 0){ // if we do not have coordinate data both lat and long will be set to 0 so we don't draw
noStroke();
fill(50,50,map(magnitude,2.5,4,0,255),50); // calculate a fill colour based on earthquake magnitude
ellipse( longX + 180, (height - (latY + 90)), map(magnitude,2.5,6,0,30) , map(magnitude,2.5,6,0,30));
//draw a ellipse earthquake coordinates,two things to note because the world is round and not flat we have flatterned our coordinated
//we have done this by converting longitude (the angular measurement ranging from 0° at the prime meridian to +180° eastward and −180° westward) directly to a X coordinate
// and latitude the directly to a y coordinate
println("latY: "+(latY +90)+ " longX: "+(longX+180)+ " magnitude: "+(magnitude));
}
}
}