Skip to content

Commit

Permalink
Updates for presentation today
Browse files Browse the repository at this point in the history
  • Loading branch information
David Humphrey committed Nov 11, 2011
1 parent 32ab065 commit c4d8767
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 3 deletions.
100 changes: 100 additions & 0 deletions examples/twitter/blprnt-twitter-demo.html
@@ -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.
9 changes: 6 additions & 3 deletions processing.js
@@ -1,6 +1,9 @@


(function(window, document, Math, undef) { (function(window, document, Math, undef) {


// Check for PhoneGap
var startupEvent = (window.device && window.device.phonegap) ? 'deviceready' : 'DOMContentLoaded';

var nop = function(){}; var nop = function(){};


var debug = (function() { var debug = (function() {
Expand Down Expand Up @@ -19719,7 +19722,7 @@
* Automatic initialization function. * Automatic initialization function.
*/ */
var init = function() { var init = function() {
document.removeEventListener('DOMContentLoaded', init, false); document.removeEventListener(startupEvent, init, false);


var canvas = document.getElementsByTagName('canvas'), var canvas = document.getElementsByTagName('canvas'),
filenames; filenames;
Expand Down Expand Up @@ -19803,15 +19806,15 @@
*/ */
Processing.disableInit = function() { Processing.disableInit = function() {
if(isDOMPresent) { if(isDOMPresent) {
document.removeEventListener('DOMContentLoaded', init, false); document.removeEventListener(startupEvent, init, false);
} }
}; };
//#endif //#endif


if(isDOMPresent) { if(isDOMPresent) {
window['Processing'] = Processing; window['Processing'] = Processing;
//#if PARSER //#if PARSER
document.addEventListener('DOMContentLoaded', init, false); document.addEventListener(startupEvent, init, false);
//#endif //#endif
} else { } else {
// DOM is not found // DOM is not found
Expand Down

0 comments on commit c4d8767

Please sign in to comment.