Permalink
Browse files

Merge pull request #9 from humphd/master

Stuff for today
  • Loading branch information...
2 parents 20285d2 + a71ba5c commit 97b715c6c9382dced58e84520bb77dd0adf112bb David Humphrey committed Nov 11, 2011
@@ -12,11 +12,6 @@
<p>New built-in types are added to Processing: motionX, motionY, motionZ. These are floats indicating the position of the device along the x, y, and z axis. Each has a value bewtween -1 and 1. Devices that do not support DeviceMotion events will have motionX == motionY == motionZ == 0 by default.</p>
<script type="text/processing" data-processing-target="sketch">
- // New values, motion{X|Y|Z} come from processing-mobile.js
- // and are floats (double) between -1 and 1, indicating position
- // along the axis of the device. If the device does not support
- // DeviceMotion events, 0 is used for all three.
-
int x, y;
float lastTheta = 0;
float easing = 0.1;
@@ -26,7 +21,7 @@
}
void locationChanged() {
- println(coords.latitude);
+ println(coords.longitude + ", " + coords.latitude);
}
void draw() {
@@ -54,8 +49,6 @@
int compassY = 100 * cos(radians(lastTheta));
ellipse(width/2 - compassX, height/2 - compassY, 20, 20);
}
-
-// println(motionX + ', ' + motionY + ', ' + motionZ);
}
</script>
<canvas id="sketch"></canvas>
@@ -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.
View
@@ -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,15 +19806,15 @@
*/
Processing.disableInit = function() {
if(isDOMPresent) {
- document.removeEventListener('DOMContentLoaded', init, false);
+ document.removeEventListener(startupEvent, init, false);
}
};
//#endif
if(isDOMPresent) {
window['Processing'] = Processing;
//#if PARSER
- document.addEventListener('DOMContentLoaded', init, false);
+ document.addEventListener(startupEvent, init, false);
//#endif
} else {
// DOM is not found

0 comments on commit 97b715c

Please sign in to comment.