Monday, March 14, 2011

Processing data:


So if you were paying attention to my last post, I had discussed "scraping" or else, the retrieval of data from other sources and how it is possible to use the data and manipulate it in other programmes, such as Flash and Processing to name but two.

There's a wide variety of ways of doing this, quite some time ago we had engaged in a project that allowed the user to integrate content that was ripped from an xml file and use the data in Actionscript.

Another manner of doing this is by using the program Processing, which allows the user to graphically represent data from a dynamic source, for instance, the last item that I had made a spreadsheet out of was the "largest population per country" statistic and made it look something like this...


My document is public on google documents, so just replace my email address and password with your own and use the same key.

As a matter of fact that same system can be used for any document you have, just replace the key, with the key thats held within the url of your document in question and change the variables to fit your own document.

The code


PFont fontA;
SimpleSpreadsheetManager sm;

void setup() {
size(800,600);
background(156);

SimpleSpreadsheetManager sm = new SimpleSpreadsheetManager();
sm.init("myProjectName","starless.skies.burn.to.ash@gmail.com", "retard");
sm.fetchSheetByKey("0AjdwwVu3M62OdFR0UHdlc183SjNES3l4RzRXQXhGYnc", 0);


for (int i=0; i < sm.currentTotalRows-1; i++) {
String valone = sm.getCellValue(1,i);
String valtwo = sm.getCellValue(2, i);
int numberz = int(valtwo);

int scrattocks = (numberz/5000000);

println(valone + " : " + numberz);

String party = valtwo;



fontA = loadFont("ACaslonPro-BoldItalic-48.vlw");
textFont(fontA, 32);
noLoop();

if (valone.equals("China")){
color inside = color(127, 0, 0, 127);
fill(inside);
println("seems to be ok " + String.valueOf(valone) + i);
ellipse(random (20, width-20),random (0, height), scrattocks, scrattocks);
text("China", 100, 150);
};

if (valone.equals("India")){
color inside = color(48, 139, 206, 127);
fill(inside);
println("seems to be ok " + String.valueOf(valone) + i);
ellipse(random (20, width-20),random (0, height), scrattocks, scrattocks);
text("India", 200, 150);
};
if (valone.equals("USA")){
color inside = color(48, 39, 26, 127);
fill(inside);
println("seems to be ok " + String.valueOf(valone) + i);
ellipse(random (20, width-20),random (0, height), scrattocks, scrattocks);
text("USA", 300, 150);
};
if (valone.equals("Indonesia")){
color inside = color(127, 205, 155, 127);
fill(inside);
println("seems to be ok " + String.valueOf(valone) + i);
ellipse(random (20, width-20),random (0, height), scrattocks, scrattocks);
text("Indonesia", 300, 150);
};
if (valone.equals("Brazil")){
color inside = color(25, 75, 125, 127);
fill(inside);
println("seems to be ok " + String.valueOf(valone) + i);
ellipse(random (20, width-20),random (0, height), scrattocks, scrattocks);

};

if (valone.equals("Pakistan")){
color inside = color(55, 105, 155, 127);
fill(inside);
println("seems to be ok " + String.valueOf(valone) + i);
ellipse(random (20, width-20),random (0, height), scrattocks, scrattocks);

};

if (valone.equals("Bangladesh")){
color inside = color(14, 165, 212, 127);
fill(inside);
println("seems to be ok " + String.valueOf(valone) + i);
ellipse(random (20, width-20),random (0, height), scrattocks, scrattocks);

};

if (valone.equals("Nigeria")){
color inside = color(123, 175, 10, 127);
fill(inside);
println("seems to be ok " + String.valueOf(valone) + i);
ellipse(random (20, width-20),random (0, height), scrattocks, scrattocks);

};

if (valone.equals("Russia")){
color inside = color(0, 10, 100, 127);
fill(inside);
println("seems to be ok " + String.valueOf(valone) + i);
ellipse(random (20, width-20),random (0, height), scrattocks, scrattocks);

};

if (valone.equals("Japan")){
color inside = color(23, 133, 245, 127);
fill(inside);
println("seems to be ok " + String.valueOf(valone) + i);
ellipse(random (20, width-20),random (0, height), scrattocks, scrattocks);

};

};



};




No comments:

Post a Comment