Tuesday 13 April 2010

Processing: Development Part 3

Adding the XML feeds

The most awkward task now is to effectively extract data from the Plymouth Universities ARCH-OS system and place it onto each circle to represent visual data using colour as the basis of displaying the results..

I will need to start with importing the xml from the processing libraries along with each XML Element I need to use.

import processing.xml.*;

XMLElement xml;
XMLElement[] title;
XMLElement[] pubDate;
XMLElement[] value;

Each of these elements identify titles, dates and values from the feeds.
In my void setup(){ I have to add code to string the website address and use the getChildren command to extract every piece of data from the server.

For the XML feed I have chosen windspeed. This matches my criteria because of the movement is that of a wind vane spinning. To indicate the windspeed I may choose various colours to represent the speeds.

void setup
String url ="http://x2.i-dat.org/archos/archive.rss?source=bms_.WindSpeed";
XMLElement xml = new XMLElement(this, url);
title = xml.getChildren("channel/item/title");
pubDate = xml.getChildren("channel/item/pubDate");
value = xml.getChildren("channel/item/description");

The code below displays the use of .getContent().charAt(1)) which is used to extract the numerical values needed to represent the data onto my sketch. By using another For Loop, I can simply print the data to the sketch with the help of 'println(a+" "+c)'. So this is extracting the values in a loop and producing them onto the sketch.

void update
for (int j = 0; j < 5; j++){
int a = int(title[j].getContent().charAt(1));
int b = int(pubDate[j].getContent().charAt(1));
int c = int(value[j].getContent().charAt(2));
println(a+" "+c)

Colour Changing
To represent the data onto my circles, I need to create an If/Else statement from the code above. I firstly need to create three new floats in the class Circle area which are:
float greenslow = 255;
float bluemed = 255;
float redfast = 255;

Green is slow, blue is medium and red is fast. These display the speeds of the wind depending on the winds speeds.

The code below shows the last part of the code I have used. The if/else statement is basically saying that if the value of the feed drops below 50, it changes colour to green, if it's above 50 then it will remain red showing that it's fast.

//If/Else statement: Colour changing to display speeds.
if (c <= 50) {
greenslow = 255;
bluemed = 18;
redfast = 0;
}
else if (c > 51) {
greenslow = 0;
bluemed = 0;
redfast = 255;

}
//Fill the greenslow,bluemed and redfast with colour
fill(greenslow,bluemed,redfast);

ellipse(xpos, ypos, diameter, diameter);
}
}
}

This last snippet of code shows that the greenslow, bluemed and redfast has been put into the fill to display the colours and the ellipse uses the xpos, ypos and diameters to basically make the ellipses travel in a circular motion.

No comments:

Post a Comment