//Build an ArrayList to hold all of the words that we get from the imported tweets
ArrayList<String> words = new ArrayList();
ConfigurationBuilder cb;
Twitter twitter;
Query query;
//These two variables are used to tweak the size and position of the names
int nameSizeMultiplier = 20;
int namePositionAdjustment = 150;
//The number of times each word comes up in the Twitter search
int cainWords = 0;
int perryWords = 0;
int bachmannWords = 0;
int paulWords = 0;
int romneyWords = 0;
int americanWords = 0;
int jobsWords = 0;
int economyWords = 0;
void setup() {
//Set the size of the stage, and the background to black.
size(800,600);
background(0);
smooth();
cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("4gi93D8y2nkadut37JcfA");
cb.setOAuthConsumerSecret("pAURDlB571afctTySuIcEczwoXCLxyN48panfpDeSQ");
cb.setOAuthAccessToken("1532481-B4KJUH0uSjdaQE0jVgi3B3BoIk5XbyxqzuNhSTstx8");
cb.setOAuthAccessTokenSecret("NQAANu41p6p2MYHL3rCej7QGk7KTAr8UiGDs7UoMKo");
//Make the twitter object and prepare the query
twitter = new TwitterFactory(cb.build()).getInstance();
query = new Query("#GOP");
query.setRpp(100);
updateTwitter();
}
void draw() {
//If 30 seconds have passed, run it again:
if (frameCount % 900 == 0)
{
updateTwitter(); //This funcion runs the search again and updates the variables
// See below for the function definition
}
background(0);
//Draw a faint black rectangle over what is currently on the stage so it fades over time.
fill(0,1);
rect(0,0,width,height);
//Draw the words at the appropriate relative size (based on the number of times they occur)
fill(255,random(50,150));
//Try making the query request.
try {
QueryResult result = twitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();
for (int i = 0; i < tweets.size(); i++) {
Tweet t = (Tweet) tweets.get(i);
String user = t.getFromUser();
String msg = t.getText();
Date d = t.getCreatedAt();
println("Tweet by " + user + " at " + d + ": " + msg);
//Break the tweet into words
String[] input = msg.split(" ");
for (int j = 0; j < input.length; j++) {
//Put each word into the words ArrayList
words.add(input[j]);
}
};
}
catch (TwitterException te) {
println("Couldn't connect: " + te);
};
for (int j = 0; j < words.size(); j++)
{
String word1 = words.get(j);
if (word1.contains("cain") || word1.contains("Cain"))
{
cainWords++;
}
if (word1.contains("perry") || word1.contains("Perry"))
{
perryWords++;
}
if (word1.contains("bachmann") || word1.contains("Bachmann"))
{
bachmannWords++;
}
if (word1.contains("paul") || word1.contains("Paul"))
{
paulWords++;
}
if (word1.contains("romney") || word1.contains("Romney"))
{
romneyWords++;
}
if (word1.contains("american") || word1.contains("American"))
{
americanWords++;
}
if (word1.contains("jobs") || word1.contains("Jobs"))
jobsWords++;
}
println("Number of Cain Words is " + cainWords);
println("Number of Perry Words is " + perryWords);
println("Number of Bachmann Words is " + bachmannWords);
println("Number of Paul Words is " + paulWords);
println("Number of Romney Words is " + romneyWords);
println("Number of American Words is " + americanWords);
println("Number of Jobs Words is " + jobsWords);
println("Number of Economy Words is " + economyWords);
}
First off I'd just like to say that I am not a programmer. This project is for school and I took it on to help myself and my group members as I do have some experience and familiarity with javascript, but I refuse to call myself a programmer
. The project we are trying to complete is to use processing to recognize a particular file on a drive. For example, you plug in your flash drive, it searches for a text file, and does an action if it does or does not find it. At the moment our code recognizes our file, plays audio when the file is or is not there, and displays an image. However, we want our code to play an animation instead of displaying an image. Our animation is 200+ frames long. I've been trying different array methods and haven't got much to work. Below is our WORKING code. If anyone could help with displaying a 200+ frame animation instead of the image we have listed it would be much appreciated!
First off I'd just like to say that I am not a programmer. This project is for school and I took it on to help myself and my group members as I do have some experience and familiarity with javascript, but I refuse to call myself a programmer
. The project we are trying to complete is to use processing to recognize a particular file on a drive. For example, you plug in your flash drive, it searches for a text file, and does an action if it does or does not find it. At the moment our code recognizes our file, plays audio when the file is or is not there, and displays an image. However, we want our code to play an animation instead of displaying an image. Our animation is 200+ frames long. I've been trying different array methods and haven't got much to work. Below is our WORKING code. If anyone could help with displaying a 200+ frame animation instead of the image we have listed it would be much appreciated!