import simpleML.*; XMLRequest xmlRequest; SingleWord [] singleword; //Array of objects for displaying single clickable words, parsed from NYTimes headlines String [] theheadlines; //Original NYTimes headliens, grabbed via XML feed String [] headlinewords; //Array of words for a single headline String [] twitterheadlines; //"Headlines" from Twitter String [] twitter; //Array of twitter feeds, from the Twitter headlines String wordString; //String variable for passing the words from the original headlines into the "SingleWord" class to be displayed String twitterRequest; //String variable for passing the clicked NYTimes headline word into a Twitter XML request int doubleline; String delimiters = " ,.?!;:[]'"; //Delimiters for parsing the headlines into word objects //int indexW = 0; //Index for "thewords" array int indexH = 2; //Index for "theheadlines" array, starting at 2 because we want to skip the first two headlines in the NYTimes feed PFont f; //Declare font object PFont t; boolean loaded; //Set boolean so that draw loop only executes after XML request has been completed int tx = 10; //X value of twitter feeds int ty = 200; //Y value of twitter feeds void setup() { size(1024,600); f = createFont( "Arial",24,true); t = createFont("Arial", 15, true); textFont(t); textFont(f); frameRate(30); //First XML request, NYTimes headlines xmlRequest = new XMLRequest(this, "http://www.nytimes.com/services/xml/rss/nyt/US.xml"); xmlRequest.makeRequest(); } void draw() { background(0); //If the singleword array object is not null, then display all the single words in one NYT headline if (singleword != null) { for (int s = 0; s < singleword.length; s++) { singleword[s].display(); singleword[s].movepulse(); } if (singleword[0].swa >= 200) { indexH++; if (indexH >= theheadlines.length){ indexH= 2; } newNYTHeadline(); } // hover(); wordClicked(); } if (twitter != null){ //println("callcheck"); int tempy = 250; textFont(t); for(int t = 0; t < twitter.length; t++){ fill(200); text(twitter[t], tx, tempy); tempy += 20; } } } void netEvent(XMLRequest ml) { //If boolean loaded is fallse, create array "theheadlines" using NYT headlines (between "title" tags), //then run function new NTYHeadlne if(!loaded) { theheadlines = ml.getElementArray("title"); newNYTHeadline(); } else { twitterheadlines = ml.getElementArray( "title" ); for (int i = 0; i < twitterheadlines.length; i++ ) { println(twitterheadlines[i]); twitter = twitterheadlines; ty =300; } } } void newNYTHeadline() { //Split each NYT headline, starting with index 2, into an array string of words //using the delimiters defined above; name that array "headlinewords" headlinewords = splitTokens(theheadlines[indexH],delimiters); //Create an array object called "singleword" that is as long as the number of words in each NYT headline singleword = new SingleWord[headlinewords.length]; float x = 100; float y = 0; float a = 6; float sp = 4; for (int s = 0; s < headlinewords.length; s++) { singleword[s] = new SingleWord (headlinewords[s], x, y, a, sp); x += textWidth(headlinewords[s]) + 5; y = random(1); a = random(6,25); sp = random(3,5); } } void hover(){ for (int m = 0; m < headlinewords.length; m++) { if (mouseX > singleword[m].swx && (mouseX < singleword[m].swx + textWidth(headlinewords[m]))) { singleword[m].hoverswitch = true; } else { } if(singleword[m].hoverswitch){ singleword[m].swa = 255; singleword[m].hoverswitch = false; } } } void wordClicked(){ for (int c = 0; c < headlinewords.length; c++) { if (mouseX > singleword[c].swx && (mouseX < singleword[c].swx + textWidth(headlinewords[c]))) { if(mousePressed) { singleword[c].swa = 0; twitterNabber(singleword[c].swordstring); } } } } void twitterNabber(String getrequest) { twitterRequest = getrequest; println(twitterRequest); xmlRequest = new XMLRequest(this, "http://search.twitter.com/search.atom?q=" + twitterRequest); loaded = true; xmlRequest.makeRequest(); } class SingleWord { float swx,swy; float swfs; float swa; float swspeed; boolean hoverswitch; String swordstring; SingleWord(String tempString, float tempX, float tempY, float tempA, float tempSpeed) { swordstring = tempString; swx = tempX; swy = tempY; swa = tempA; swspeed = tempSpeed; } void display() { textFont(f); fill(255,swa); textAlign(LEFT); // if(swx <= 600){ text(swordstring, swx, swy); // doubleline = 0; /* } else { println("woah" + swordstring); doubleline = 60; swx = 50; float tempswy = swy + 50; swx += textWidth(swordstring); println(tempswy); text(swordstring, swx, tempswy); } */ } void movepulse() { swy = swy + swspeed; if (swy + doubleline >= 150) { swy = 150; } swa = swa + 1; } }