Skip to content

Instantly share code, notes, and snippets.

@rhathaway
Created December 12, 2011 06:31
Show Gist options
  • Save rhathaway/1465405 to your computer and use it in GitHub Desktop.
Save rhathaway/1465405 to your computer and use it in GitHub Desktop.
twitter glyphs WIP #1
class Glyph {
int x, y, glyphsize;
Glyph() {
x = 10;
y = 10;
glyphsize = 10;
}
void paint(int i) {
smooth();
noStroke();
ellipse(x + i * 10, y, glyphsize, glyphsize);
}
void paint2(int i) {
smooth();
noStroke();
ellipse(x + i * 10, y + 50, glyphsize, glyphsize);
}
}
import com.francisli.processing.http.*;
//// variable declaration of an two arrays of Glyph objects
Glyph[] happyGlyphs;
Glyph[] sadGlyphs;
//PFont titleFont;
HttpClient client;
HttpRequest happySearch;
HttpRequest sadSearch;
void setup() {
size(720, 480);
frameRate(24);
client = new HttpClient(this, "search.twitter.com");
//// using SSL is optional, but recommended
client.useSSL = true;
//// turn on OAuth request signing
client.useOAuth = true;
//// set up OAuth signing parameters
client.oauthConsumerKey = "[consumer key]";
client.oauthConsumerSecret = "[consumer secret]";
client.oauthAccessToken = "[access token]";
client.oauthAccessTokenSecret = "[access token secret]";
//// set up POST params
HashMap params = new HashMap();
// positive tweets about the weather within 15mi of san francisco
params.put("q", "weather :) geocode:37.781157,-122.398720,15mi");
happySearch = client.GET("/search.json", params);
HashMap params2 = new HashMap();
// negative tweets about the weather within 15mi of san francisco
params2.put("q", "weather :( geocode:37.781157,-122.398720,15mi");
sadSearch = client.GET("/search.json", params2);
//// variable assignment- we instantiate a new array of Glyph objects with size 200
happyGlyphs = new Glyph[200];
for (int i = 0; i < happyGlyphs.length; i = i + 1) {
happyGlyphs[i] = new Glyph();
}
sadGlyphs = new Glyph[200];
for (int i = 0; i < sadGlyphs.length; i = i + 1) {
sadGlyphs[i] = new Glyph();
}
}
void responseReceived(HttpRequest request, HttpResponse response) {
println(response.statusCode + ": " + response.statusMessage);
println(response.getContentAsString());
JSONObject content = response.getContentAsJSONObject();
if (request == happySearch) {
JSONObject happyResults = content.get("results");
happyGlyphs = new Glyph[happyResults.size()];
for (int i = 0; i < happyResults.size(); i++) {
JSONObject tweet = happyResults.get(i);
Glyph tg = new Glyph();
happyGlyphs[i] = tg;
}
}
else if (request == sadSearch) {
JSONObject sadResults = content.get("results");
sadGlyphs = new Glyph[sadResults.size()];
for (int i = 0; i < sadResults.size(); i++) {
JSONObject tweet = sadResults.get(i);
Glyph tg = new Glyph();
sadGlyphs[i] = tg;
}
}
}
void draw() {
background(46, 98, 206);
smooth();
println(happyGlyphs.length);
for (int i = 0; i < happyGlyphs.length; i = i + 1) {
happyGlyphs[i].paint(i);
}
println(sadGlyphs.length);
for (int i = 0; i < sadGlyphs.length; i = i + 1) {
sadGlyphs[i].paint2(i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment