twittervisualiser

String searchTerm = “monkey”;
PFont fontA;
long lastId;
int lastSecond;
float total=540;
float rx=random(980);
float ry=random(450);
float rc=random(255);
int value=0;

void setup(){
size(980,500);
background(0);
fill(255);
rect (0,498,980,2);
smooth();
fontA = loadFont(“AndaleMono-12.vlw”);
textFont(fontA, 12);
text(“Searching for “+searchTerm+”…”, 0, 470);

//this searches for the search term and notes the id number of the most recent tweet
//containing that search term. from here on in, all tweets with a later id number are new tweets
Twitter twitter = new Twitter();
try{
Query query = new Query(searchTerm);
QueryResult result = (QueryResult) twitter.search(query);

java.util.List tweets = result.getTweets();
Tweet t = (Tweet) tweets.get(0);
lastId = t.getId();
// println(“Searching for “+searchTerm+”…”);

}
catch (Exception e){
System.out.println(e);
}
lastSecond = second();
}

void mousePressed() {
if(value == 0) {
value = 255;
} else {
value = 0; }}

void draw(){
//background(55);
fill(90,mouseY,255);
//fill(90,90,255);
rect (0,0,980,450);

// David
fill(255,1,rc);
line (rx,111,450,450) ;
rect (rx,10,50,100);
rect (rx,100,200,200);
quad (ry,314,767,323,453,450,321,450);
ellipse (ry,390,110,110);
fill(ry,255,ry);
ellipse(rx,450-ry-135,135,135);
ellipse(ry,400-rx-rx,ry,rx);

//Honour
//house
fill (171,6,248);
rect (760,90,100,100);
fill (0,45,206);
triangle (814,37,756,92,860,90);
//fill (255,0,75);
fill (value,value,190);
rect (769.5,105,25,25);
rect (820,105,25,25);
rect (800.5,159.5,15,30);

//snowman
//body
fill (9247,247,235);
ellipse (total, 140, 100,100);
//head
ellipse (total,140-60,50,50);
//eyes
fill (0,255,0);
ellipse (total-10,140-70,10,10);
ellipse (total+5,140-68,10,10);

// Jamie
//body
fill(3,61,178);
rect(167,245,66,85);
//head
fill(243,223,188);
ellipse(200,215,60,57.5);
//right leg
quad (223, 330, 233, 330, rc+66, 390, rc+56, 390);
//left leg
quad (167, 330, 177, 330, rc+10, 390, rc, 390);
//right arm
quad (157, 245, 167, 245, rc, 296, rc-10, 296);
//left arm
quad (233, 245, 243, 245, rc+76, 296, rc+66, 296);

// Becca
fill(26,169,239);
//neck
rect(720,211,24,84);
//head
ellipse(722,211,58,48);
fill(26,169,239);
// eye
ellipse(707,204,8,8);
// beak
triangle(694,211,696,219,680,213);
// leg
rect(807,348,12,40);
// foot
triangle(806,388,818,388,792,385);
fill (35,135,235);
//body
ellipse(820,291,210,120);
//wing
triangle (775,286,930,(map(ry, 0, 450, 200, 350)),870,273);

int now = second();
//every 2 seconds
if (now-lastSecond > 2 || (lastSecond – now < 50 && lastSecond - now > 0)){
// if (now-lastSecond > 1 || (lastSecond – now < 50 && lastSecond - now > 0)){
//do a new twitter search since the last ID
Twitter twitter = new Twitter();
try{
Query query = new Query(searchTerm);
query.setSinceId(lastId);
QueryResult result = (QueryResult) twitter.search(query);
java.util.List tweets = result.getTweets();
total+=tweets.size();
if (tweets.size()>0){
Tweet t = (Tweet) tweets.get(0);
lastId = t.getId();
String user = t.getFromUser();
String msg = t.getText();
Date d = t.getCreatedAt();

println(“Tweet by ” + user + ” at ” + d + “: ” + msg);

fill(0);
rect (0,450,980,450);
fill(255);
rect (0,498,980,2);
text(“Tweet by ” + user + ” at ” + d + “: “, 0, 470);
text(msg, 0, 485);

if (total>1){total=0+random(630);}

if (rx>1){rx=0+random(700);}
if (ry>1){ry=0+random(450);}
if (rc>1){rc=0+random(255);}

}
}
catch (Exception e){
System.out.println(e);
}
lastSecond = now;
}

}

Leave a Reply

*Required fields/Mail will not be published
  • Comments
  • Print
  • Share/Bookmark