01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
PFont font;
PImage img;
String twitterMsgData;
Twitter myTwitter;
ArrayList tweets;
float x = 800;
int offsetX;
void setup() {
size(1800, 200);
colorMode(HSB, 360, 100, 100, 100);
img = loadImage("trans.gif");
font = createFont("V5PRC___.TTF", 30 );
textFont(font);
frameRate(30);
smooth();
noStroke();
myTwitter = new Twitter("USER", "PW");
loadTweets();
}
void draw() {
background( 0);
randomSeed(0);
int y = height/2;
if (frameCount%(30*60*5)==0)loadTweets(); //refresh every 5 min
for (int i = 0; i < tweets.size(); i++) {
Tweet t = (Tweet) tweets.get(i);
String user = t.getFromUser();
String msg = t.getText();
msg = msg.replaceAll("r|n", "");
Date d = t.getCreatedAt();
float textHeight = textAscent()+textDescent();
fill(random(255), 100, 100);
text(user+" : "+msg, x+offsetX, y);
offsetX += textWidth(msg)+textWidth(user)+textWidth(" : ");
}
image(img, -30, 0, 220, height);
pushMatrix();
rotate( PI);
image(img, -width-30, -height, 220, height);
popMatrix();
x-=5;
if (x<-offsetX-10) x = width+10;
offsetX = 0;
}
void loadTweets() {
try {
Query query = new Query("CedricKiefer");
query.setGeoCode(new GeoLocation(52.0, 13.0), 200.0, Query.KILOMETERS);
query.setRpp(3);
QueryResult result = myTwitter.search(query);
tweets = (ArrayList) result.getTweets();
}
catch (TwitterException te) {
println("Couldn’t connect: " + te);
}
}