Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updates for presentation today

  • Loading branch information...
commit c4d87675c94bb1a9205ed9606fea91ab171ead12 1 parent 32ab065
David Humphrey authored
View
100 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>
View
0  examples/twitter/index.html → examples/twitter/twitter-images.html
File renamed without changes
View
9 processing.js
@@ -1,6 +1,9 @@
(function(window, document, Math, undef) {
+ // Check for PhoneGap
+ var startupEvent = (window.device && window.device.phonegap) ? 'deviceready' : 'DOMContentLoaded';
+
var nop = function(){};
var debug = (function() {
@@ -19719,7 +19722,7 @@
* Automatic initialization function.
*/
var init = function() {
- document.removeEventListener('DOMContentLoaded', init, false);
+ document.removeEventListener(startupEvent, init, false);
var canvas = document.getElementsByTagName('canvas'),
filenames;
@@ -19803,7 +19806,7 @@
*/
Processing.disableInit = function() {
if(isDOMPresent) {
- document.removeEventListener('DOMContentLoaded', init, false);
+ document.removeEventListener(startupEvent, init, false);
}
};
//#endif
@@ -19811,7 +19814,7 @@
if(isDOMPresent) {
window['Processing'] = Processing;
//#if PARSER
- document.addEventListener('DOMContentLoaded', init, false);
+ document.addEventListener(startupEvent, init, false);
//#endif
} else {
// DOM is not found
Please sign in to comment.
Something went wrong with that request. Please try again.