forked from processing-js/processing-mobile
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Humphrey
committed
Nov 11, 2011
1 parent
32ab065
commit c4d8767
Showing
3 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,100 @@ | |||
<!DOCTYPE html> | |||
<head> | |||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |||
<title>Processing.js Twitter Demo by blprnt</title> | |||
<style> | |||
html body { | |||
margin: 0; | |||
padding: 0; | |||
background: black; | |||
} | |||
</style> | |||
<script src="../../processing.js" type="text/javascript"></script> | |||
<script src="processing-twitter.js" type="text/javascript"></script> | |||
</head> | |||
<body> | |||
<!-- | |||
A port of http://blog.blprnt.com/blog/blprnt/updated-quick-tutorial-processing-twitter by Jer Thorp's | |||
Processing Twitter demo. The twitter API is exposed to Processing.js via a JavaScript library. I | |||
built this for a demo today, it's not really production quality, but could be refined to be used | |||
as such. Click the sketch to have the word list reload from fresh tweets. | |||
--> | |||
<script id="sketch" type="application/processing"> | |||
ArrayList<String> words = new ArrayList(); | |||
|
|||
// Global ArrayList of tweets is created in processing-twitter.js | |||
// ArrayList<Tweet> tweets = new ArrayList(); | |||
|
|||
// A class representing a Tweet. Tweet objects are created in JS | |||
// and automatically placed in the tweets ArrayList (created in JS) | |||
class Tweet { | |||
public String id; | |||
public String profileName; | |||
public String profileImageUrl; | |||
public String text; | |||
public Date time; | |||
} | |||
|
|||
void setup() { | |||
// XXX: jbuck: "just subtract 10" | |||
size(window.innerWidth, window.innerHeight-10); | |||
background(0); | |||
smooth(); | |||
|
|||
// Slow things down a bit... | |||
frameRate(15); | |||
|
|||
// Start a live feed loading, results will be available in a global | |||
// ArrayList called tweets. loadTweets() is a custom method added | |||
// by processing-twitter.js | |||
loadTweets('#OWS'); | |||
|
|||
// You can also pass geolocation data to limit tweets to a geographic area | |||
// loadTweets('class', '43.7496,-79.4886,1km'); // York University | |||
} | |||
|
|||
void draw() { | |||
// If we don't have any data back from Twitter yet, bail early | |||
if (tweets.size() > 0) { | |||
// If we haven't created the words list yet, do it now | |||
for (int i = 0; i < tweets.size(); i++) { | |||
Tweet t = (Tweet) tweets.get(i); | |||
String msg = t.text; | |||
|
|||
// 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]); | |||
} | |||
} | |||
tweets.clear(); | |||
} | |||
|
|||
// If we have a word list already, draw it | |||
if (words.size() > 0) { | |||
// Draw a faint black rectangle over what is currently on the stage so it fades over time. | |||
fill(0,8); | |||
rect(0,0,width,height); | |||
|
|||
// Draw a word from the list of words that we've built | |||
int j = (frameCount % words.size()); | |||
String word = words.get(j); | |||
|
|||
// Put it somewhere random on the stage, with a random size and colour | |||
fill(255,random(50,150)); | |||
textSize((int)random(10,30)); | |||
text(word, random(width), random(height)); | |||
} | |||
} | |||
|
|||
// Rebuild the word list when the user clicks | |||
void mousePressed() { | |||
background(0); | |||
tweets.clear(); | |||
words.clear(); | |||
} | |||
</script> | |||
<canvas id="tweets"></canvas> | |||
</body> | |||
</html> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters