Twitter API: Sketch only shows last tweet
in
Programming Questions
•
1 year ago
Hi!
I don't understand code too well so please bare with me! I have no problem displaying the tweets on my sketch, but I don't know how to go about displaying them all in a timely manner one at a time (one by one). For example, after it displays a tweet for a specific duration it goes to the next one. My sketch keeps going to the last tweet (it seems that Processing can only read in 14 tweets before it re-cycles again) instead of displaying the first to last tweet.
Here's my code:
If anyone can let me know what I'm doing wrong or assist me on how to go about this, I'd really appreciate it! Thank you!
I don't understand code too well so please bare with me! I have no problem displaying the tweets on my sketch, but I don't know how to go about displaying them all in a timely manner one at a time (one by one). For example, after it displays a tweet for a specific duration it goes to the next one. My sketch keeps going to the last tweet (it seems that Processing can only read in 14 tweets before it re-cycles again) instead of displaying the first to last tweet.
Here's my code:
- PFont font;
PImage aB,bB,cB,mB,nB,oB,yB,zB,
dG,eG,fG,pG,qG,rG,
gY,hY,iY,sY,tY,uY,
jO,kO,lO,vO,wO,xO;
String[] strTweets;
float textX = width;
float textY = 70;
float alphaValue;
int counter;
int index = 0;
int x = 0;
int nextPage = 0;
void setup() {
//Initiate
size(1024,600);
//background(255,253,245);
background(233,240,242);
//background(139,122,94);
aB = loadImage("aB.png"); bB = loadImage("bB.png"); cB = loadImage("cB.png");
mB = loadImage("mB.png"); nB = loadImage("nB.png"); oB = loadImage("oB.png");
yB = loadImage("yB.png"); zB = loadImage("zB.png");
dG = loadImage("dG.png"); eG = loadImage("eG.png"); fG = loadImage("fG.png");
pG = loadImage("pG.png"); qG = loadImage("qG.png"); rG = loadImage("rG.png");
gY = loadImage("gY.png"); hY = loadImage("hY.png"); iY = loadImage("iY.png");
sY = loadImage("sY.png"); tY = loadImage("tY.png"); uY = loadImage("uY.png");
jO = loadImage("jO.png"); kO = loadImage("kO.png"); lO = loadImage("lO.png");
vO = loadImage("vO.png"); wO = loadImage("wO.png"); xO = loadImage("xO.png");
font = createFont("Arial-Bold.vlw", 60);
textFont(font);
textAlign(LEFT);
ellipseMode(CENTER);
//Styles
imageMode(CENTER);
smooth();
//Tweets
//fill(254,49,30, random(0,255));
textFont(font,17.5);
//Search Query
XMLElement rss = new XMLElement(this,
"http://search.twitter.com/search.atom?q=creativity&show_user=true");
XMLElement tweets[] = rss.getChildren("entry/title");
strTweets= new String[tweets.length];
for(int i = 0; i < tweets.length; i++) {
strTweets[i] = tweets[i].getContent();
}
}
void draw() {
switch (nextPage) {
//**CreativeStream
case 0:
background(139,122,94);
tweet2char();
break;
//**Interface/Tweets
case 1:
background(255,253,245);
tweets();
break;
}
}
void tweets () {//Scroll Tweets
fill(254,49,30);
if(index < strTweets.length) {
text(strTweets[index], textX, 220);
textX = textX - 1;
float w = textWidth(strTweets[index]);
if(textX < -w) {
textX = width;
index = (index + 1) & strTweets.length;
}
}
}
void tweet2char() {
frameRate(10);
char[][] target;
target = new char[strTweets.length][];
for(int i = 0; i<strTweets.length;i++) {
target[i] = strTweets[i].toCharArray();
fill(53,53,53,alphaValue);
if(millis() > 3000) {
if(alphaValue < 255) {
alphaValue = alphaValue + 10;
}
}
//background(255,253,245);
//background(251,254,255);
background(255,254,228);
//translate(0,50);
textAlign(CENTER);
imageMode(CENTER);
text(strTweets[i], textX+215,515, 600,100);
if(strTweets.length >= textX) {
textY = textY + 50;
//delay(1500);
//to test if tweets work
//println("this is tweet no. " + i + " tweet: " + strTweets[i]);
}
for(int j = 0;j<strTweets.length;j++) {
smooth();
char c = strTweets[i].charAt(i);
switch(c){
/*Blue fill(115,169,217);
background(115,169,217);
Light Gray fill(233,240,242);
background(233,240,242);
Green fill(160,217,37);//CYMK
background(160,217,37);
fill(185,191,15);
background(185,191,15);
Light Yellow fill(242,197,61);
background(242,197,61);
Yellow fill(242,160,7);
background(242,160,7); */
case '~':
case '!':
case '@':
case '#':
case '$':
case '%':
case '^':
case '&':
case '*':
case '(':
case ')':
case '_':
case '+':
case '`':
case '9':
case '-':
case '=':
case '{':
case '}':
case '|':
case ':':
case '"':
case '<':
case '>':
case '?':
case '[':
case ']':
case ';':
case ',':
case '.':
case '/':
case '0':
case 'a':
case 'A':
image(aB,random(200,824),random(125,375));
case 'b':
case 'B':
image(bB,random(200,824),random(125,375));
case 'c':
case 'C':
image(cB,random(200,824),random(125,375));
case '1':
case 'd':
case 'D':
image(dG,random(200,824),random(125,375));
case 'e':
case 'E':
image(eG,random(200,824),random(125,375));
case 'f':
case 'F':
image(fG,random(200,824),random(125,375));
case '2':
case 'g':
case 'G':
image(gY,random(200,824),random(125,375));
case 'h':
case 'H':
image(hY,random(200,824),random(125,375));
case 'i':
case 'I':
image(iY,random(200,824),random(125,375));
case '3':
case 'j':
case 'J':
image(jO,random(200,824),random(125,375));
case 'k':
case 'K':
image(kO,random(200,824),random(125,375));
case 'l':
case 'L':
image(lO,random(200,824),random(125,375));
case '4':
case 'm':
case 'M':
image(mB,random(200,824),random(125,375));
case 'n':
case 'N':
image(nB,random(200,824),random(125,375));
case 'o':
case 'O':
image(oB,random(200,824),random(125,375));
case '5':
case 'p':
case 'P':
image(pG,random(200,824),random(125,375));
case 'q':
case 'Q':
image(qG,random(200,824),random(125,375));
case 'r':
case 'R':
image(rG,random(200,824),random(125,375));
case '6':
case 's':
case 'S':
image(sY,random(200,824),random(125,375));
case 't':
case 'T':
image(tY,random(200,824),random(125,375));
case 'u':
case 'U':
image(uY,random(200,824),random(125,375));
case '7':
case 'v':
case 'V':
image(vO,random(200,824),random(125,375));
case 'w':
case 'W':
image(wO,random(200,824),random(125,375));
case 'x':
case 'X':
image(xO,random(200,824),random(125,375));
case '8':
case 'y':
case 'Y':
image(yB,random(200,824),random(125,375));
case 'z':
case 'Z':
image(zB,random(200,824),random(125,375));
break;
}
}
}
}
/*int beat() {
int beat = (int)(millis()/250.) % 5 + 1;
return beat;
}*/
void keyPressed() {
if(key == CODED) {
switch(keyCode) {
case UP:
case RIGHT:
nextPage++;
break;
case DOWN:
case LEFT:
nextPage--;
break;
}
}
if(nextPage > 2) nextPage = 0;
}
If anyone can let me know what I'm doing wrong or assist me on how to go about this, I'd really appreciate it! Thank you!
1