Hi everybody,
So, I made this project that implements the twitter4j library. Basically, the sketch creates a window, displaying a background that's a solid color. It also scrapes Twitter, looking for tweets with a specific hashtag. It gets rid of the hashtag, and uses the rest of the text. The idea is that users send hex values of colors, and the sketch reads the tweet and changes the color value of background() based on that.
Here's the code I have so far:
Code:
Twitter myTwitter;
int clr;
String msg;
Runnable rn;
Thread thr1;
void setup() {
size(320, 240);
clr = #000000;
myTwitter = new Twitter("", "");
rn = new Runnable(){
public void run() {
while (true) {
try {
Query query = new Query("#colorwall");
query.setRpp(1);
QueryResult result = myTwitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();
Tweet t = (Tweet) tweets.get(0);
String user = t.getFromUser();
msg = t.getText();
Date d = t.getCreatedAt();
println("Tweet by " + user + " at " + d + ": " + msg);
msg = msg.replaceAll("#colorwall","");
println(msg);
try{
clr = Integer.valueOf(msg.replaceAll("#","").trim(),16).intValue();
println(clr);
}
catch(Exception e){}
}
catch (TwitterException te) {
println("Couldn't connect: " + te);
}
}
}
};
thr1 = new Thread(rn);
thr1.start();
}
void draw() {
background(clr);
}
Now, this works pretty well for most colors. BUT, when I try use Twitter to set background() to #0000FF, it renders as white. If it's something close, like #0000FE, it also renders as white.
I tried hardcoding it in, like this:
Code:void draw() {
background(#0000FF);
}
... and it works fine. But, if I hardcode it like this:
Code:void draw() {
background(0x0000FF);
}
... then it turns white.
The solution is probably head-smackingly simple, but I'm just not seeing it. Any help would be greatly appreciated.
Thanks!