Screen Shot 2013-01-15 at 6.57.17 PM

ICM: Data Vis: Sandy Twitter stream

For our data vis assignment this week it seemed fitting to reflect some of the activity occurring online right now in response to hurricane Sandy which hit New York City this past Monday. Tucked away in my apartment in Brooklyn most of my experience of the storm was through social networks, email listservs, and the news.

This sketch is streaming every tweet that mentions “Sandy” and printing each word of each sentence rapidly into a Perlin noise wave. I wanted to try and stream the words through wave like forms to mirror the movement pf nature + water. I feel like it is partially achieved here but would be better if I had the words/ streams printed each on their own curved line so one could read the posts. I would also like to try using a start and end date to quantify the change is tweeting activity throughout the week.

Note: the video attached runs at a slower rate than the sketch due to the Quicktime screen grab capture.

//Build an ArrayList to hold all of the words that we get from the imported tweets
ArrayList words = new ArrayList();
float theta = 0.0;
float t = 0.0;

void setup() {
//Set the size of the stage, and the background to black.
size(550, 550);
background(172, 198, 201);
smooth();
frameRate(60);

//Credentials
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(“5MCnjYjiMDiY1dAuWVXvjA”);
cb.setOAuthConsumerSecret(“IGoljGedgEpzNJq0RNgYpn0FLNRWTiHERfP4ueF8VU”);
cb.setOAuthAccessToken(“58646825-NaD7vcNHRlLBPbWfDZc7CPcBOyDmMfOZvnnZUBivc”);
cb.setOAuthAccessTokenSecret(“secretgrTp4yOcJVfIsu2GvTgL8duZAHGftdPnxQduH0bYVg”);

//Make the twitter object and prepare the query
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
Query query = new Query(“sandy”);
query.setRpp(100);

//Try making the query request.
try {
QueryResult result = twitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();

for (int i = 0; i < tweets.size(); i++) {
Tweet t = (Tweet) tweets.get(i);
String user = t.getFromUser();
String msg = t.getText();
Date d = t.getCreatedAt();
println("Tweet by " + user + " at " + d + ": " + msg);

//Break the tweet into words
String[] input = msg.split(" ");
for (int j = 0; j < input.length; j++) {
//Put each word into the words ArrayList
words.add(input[j]);
}
};
}
catch (TwitterException te) {
println("Couldn't connect: " + te);
};
}

void draw() {
theta += 0.02;
//float x = theta;
t += 0.01;
float x = t;

// float wordx = 250;
// float wordy = 250;
//Draw a faint black rectangle over what is currently on the stage so it fades over time.
fill(172, 198, 201, 25);
rect(0, 0, width, height);

//Draw a word from the list of words that we've built
int i = (frameCount % words.size());
String word = words.get(i);

/*
for (int h = 0; h <=20; h++) {
float y = sin(x)*height/2;
//draw a word
fill(0);
textSize(random(10,30));
text(word,h*10,y+height/2);
//move along x axis
x += 0.2;
}
*/

for (int v = 0; v <= 55; v++) {
float y = noise(x)*height;
//draw a word
fill(252, 205, 74);
noStroke();
textSize(random(20, 30));
text(word, v*10, y);
ellipse(v*10, y, 3, 3);
//move along x axis
x += 0.05;
}

for (int b = 0; b <= 55; b++) {
float y = noise(x)*height;
//draw a word
fill(0, 0, 0, 200);
noStroke();
textSize(random(20, 30));
text(word, b*20, y);
ellipse(b*10, y, 3, 3);
//move along x axis
x += 0.05;
}

//draw an ellipse for each new word
//Put it somewhere random on the stage, with a random size and colour
// fill(0,random(50,150));
// ellipse(wordx,wordy, random(width), random(height));
}

NEW TRY TO MAP FROM START DATE (10/29/12) TO END DATE (11/6/12):
//Consumer key 5MCnjYjiMDiY1dAuWVXvjA
//Consumer secret IGoljGedgEpzNJq0RNgYpn0FLNRWTiHERfP4ueF8VU
//Access token 58646825-NaD7vcNHRlLBPbWfDZc7CPcBOyDmMfOZvnnZUBivc
//Access token secretgrTp4yOcJVfIsu2GvTgL8duZAHGftdPnxQduH0bYVg

//Build an ArrayList to hold all of the words that we get from the imported tweets
ArrayList words = new ArrayList();
float theta = 0.0;
float t = 0.0;

Calendar from = new GregorianCalendar(2012, 10, 29), to = new GregorianCalendar(2012, 11, 6), middle = (Calendar)from.clone();
int daysBetween = 0;

void setup() {
//Set the size of the stage, and the background to black.
size(550,550);
background(172,198,201);
smooth();
frameRate(60);

//Credentials
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(“5MCnjYjiMDiY1dAuWVXvjA”);
cb.setOAuthConsumerSecret(“IGoljGedgEpzNJq0RNgYpn0FLNRWTiHERfP4ueF8VU”);
cb.setOAuthAccessToken(“58646825-NaD7vcNHRlLBPbWfDZc7CPcBOyDmMfOZvnnZUBivc”);
cb.setOAuthAccessTokenSecret(“secretgrTp4yOcJVfIsu2GvTgL8duZAHGftdPnxQduH0bYVg”);

//Make the twitter object and prepare the query
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
Query query = new Query(“sandy”);
query.setRpp(100);

query.setSince(“2012-10-29″);
query.setUntil(“2012-11-06″);

while(middle.before(to)){
middle.add(Calendar.DAY_OF_MONTH, 1);
daysBetween++;
}
middle.add(Calendar.DAY_OF_MONTH, daysBetween * (-1) / 2);

//Try making the query request.
try {
QueryResult result = twitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();

for (int i = 0; i < tweets.size(); i++) {
Tweet t = (Tweet) tweets.get(i);
String user = t.getFromUser();
String msg = t.getText();
Date d = t.getCreatedAt();
println(“Tweet by ” + user + ” at ” + d + “: ” + msg);

//Break the tweet into words
String[] input = msg.split(” “);
for (int j = 0; j < input.length; j++) {
//Put each word into the words ArrayList
words.add(input[j]);
}
};
}
catch (TwitterException te) {
println(“Couldn’t connect: ” + te);
};
}

void draw() {
fill(0,1);
rect(0,0,width,height);

//Draw a word from the list of words that we’ve built
int i = (frameCount % words.size());
String word = words.get(i);

//Put it somewhere random on the stage, with a random size and colour
fill(255);
for (int j = 0; j < width; j++){
daysbetween ++;
}

/*
for (int h = 0; h <=20; h++) {
float y = sin(x)*height/2;
//draw a word
fill(0);
textSize(random(10,30));
text(word,h*10,y+height/2);
//move along x axis
x += 0.2;
}

for (int v = 0; v <= 55; v++) {
float y = noise(x)*height;
//draw a word
fill(222,164,4);
noStroke();
textSize(random(10,12));
text(word,v*10,y);
ellipse(v*10,y,3,3);
//move along x axis
x += 0.05;
}

for (int b = 0; b <= 55; b++) {
float y = noise(x)*height;
//draw a word
fill(255,189,5);
noStroke();
textSize(random(10,12));
text(word,b*20,y);
ellipse(b*10,y,3,3);
//move along x axis
x += 0.05;
}
*/

}