Programming Basics Question: how to replicate a process - how to turn process into a function?
in
Programming Questions
•
4 months ago
Hello,
Can anyone help me understand how to turn a process into a function or make make into a variable. I'm not sure I'm using the the right words. I have the following xml sketch which uses twitter's search feature to pull tweets. Currently, you can only use one search term. I would like to replicate code some how in order to search different terms simultaneously and draw them in different colors. I've mess around with a code for a while but haven't had much success. Would greatly appreciate any tips.
Thanks,
Bo
Code:
Can anyone help me understand how to turn a process into a function or make make into a variable. I'm not sure I'm using the the right words. I have the following xml sketch which uses twitter's search feature to pull tweets. Currently, you can only use one search term. I would like to replicate code some how in order to search different terms simultaneously and draw them in different colors. I've mess around with a code for a while but haven't had much success. Would greatly appreciate any tips.
Thanks,
Bo
Code:
- // Display a twitter feed in scrolly text, along with a bar that shows how many tweets we've seen
PFont font_zigg;
int newmills;
int oldmills;
int j = 0;
int textpos = 25;
String str_tweets[];
XML xml;
void setup(){
xml = loadXML("http://search.twitter.com/search.atom?q=life"); // life - // xml = loadXML("http://search.twitter.com/search.atom?q=life"); // death
XML tweets[] = xml.getChildren("entry/title");
XML users[] = xml.getChildren("entry/author/name");
size(1000, 100);
background(0);
smooth();
font_zigg = loadFont("Ziggurat-HTF-Black-32.vlw");
textFont(font_zigg, 18);
/// Now lets convert this to a String array, so we can work with the results as strings.
str_tweets = new String[tweets.length];
for(int i = 0; i < tweets.length; i++){
str_tweets[i] = users[i].getContent() + ": " + tweets[i].getContent();
}
// Initialize the time we started running.
oldmills = millis(); // don't initialize where you declare it. millis() gives a strange answer there.
println("tweet " + j + " should be " + str_tweets[j]); // just for debugging.
}
void draw(){
// Draw tweet contents
if (j < str_tweets.length) {
// newmills represents the current time, which we can check against the last time check.
newmills = millis();
// this creates a delay in betweeen displaying each tweet (in milliseconds).
if (newmills > oldmills + 4000) {
textpos = 25;
oldmills = newmills;
j++;
if (j < str_tweets.length) {
// stop it from crashing on the last increment
println("tweet " + j + " should be " + str_tweets[j]); // just for debugging.
}
} // end if newmills..
else {
// scroll the text to the left
background(0);
fill(255, 255, 0);
rect(25, 20, (j+1) * 10, 20);
textpos = textpos - 1;
text(str_tweets[j], textpos, 70);
}
} // end if i < str_tweets.length
} // end draw
1