From 3d94eb6b152324cc1fd83ce93df5d787faa39872 Mon Sep 17 00:00:00 2001 From: Christopher De Cairos Date: Fri, 3 Jun 2011 10:31:01 -0400 Subject: [PATCH] added processing plugin files and resources --- plugins/processing/popcorn.processing.html | 91 ++++++ plugins/processing/popcorn.processing.js | 329 +++++++++++++++++++++ plugins/processing/test.pjs | 38 +++ plugins/processing/test2.pjs | 26 ++ 4 files changed, 484 insertions(+) create mode 100644 plugins/processing/popcorn.processing.html create mode 100644 plugins/processing/popcorn.processing.js create mode 100644 plugins/processing/test.pjs create mode 100644 plugins/processing/test2.pjs diff --git a/plugins/processing/popcorn.processing.html b/plugins/processing/popcorn.processing.html new file mode 100644 index 0000000..98b0f2f --- /dev/null +++ b/plugins/processing/popcorn.processing.html @@ -0,0 +1,91 @@ + + + + Popcorn processing Plug-in Demo + + + + + + + +

Popcorn processing Plug-in Demo

+ +
+ +
+
+

This is within a DIV and was created by sending a string in "sketch:

+

> pause at 1 and resume at 5 seconds.

+
+
+

This is within a DIV and was created by sending a file in the sketch function

+

> pause at 5 and resume at 10 seconds. Then Pause again at 20 to 25 seconds to test multiple instructions

+
+

This is within a Canvas and was created by it having it's own sketch file

+

> pause at 10 and resume at 15 seconds.

+ + +
+ Call Function Test +
+

This is within a DIV and was created by sending a file in the sketch function

+

> change square to blue at 20 seconds.

+
+ \ No newline at end of file diff --git a/plugins/processing/popcorn.processing.js b/plugins/processing/popcorn.processing.js new file mode 100644 index 0000000..d6da226 --- /dev/null +++ b/plugins/processing/popcorn.processing.js @@ -0,0 +1,329 @@ +// PLUGIN: Processing +/** +* Processing popcorn plug-in +*/ + +(function (Popcorn) { +/** +* ajax +* Author: Processing.js Community & Benjamin Chalovich (ben1amin) +* Date: 30/03/2011 +* Parameters: +* url : the url you want to fetch string data from +* returns: void +*/ +var ajax = function ajax(url) { + try{ + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, false); + xhr.setRequestHeader("If-Modified-Since", "Fri, 01 Jan 1960 00:00:00 GMT"); + xhr.send(null); + // failed request? + if (xhr.status !== 200 && xhr.status !== 0) { return false; } // Changed for the processing plug-in + return xhr.responseText; + }catch(err){ + return false; + } +}; + /** +* checkIfProcessingExists +* Author: Benjamin Chalovich (ben1amin) +* Date: 30/03/2011 +* Parameters: +* id : The id you wish to check to see if it is already initialized +* returns: true - A processing sketch is already running with that ID +* false - That sketch is not already running +*/ +var checkIfProcessingExists = function(id){ + //checks to see if the sketch has already been created + return(typeof(Processing.instanceIds[id])!='undefined'); +} + /** + * Authors note: This should be added to the Processing library +* addProcessingInstance: adds a processing instance to the DOM based on a given ID (starts it) +* Author: Processing.js Community & Benjamin Chalovich (ben1amin) +* Date: 30/03/2011 +* Parameters: +* canvasID : the id of the canvas (that has a processing data source defined) that you wish to be initialized +* returns: void +*/ + var addProcessingInstance = function(canvasID) { + // Ensures that you do not instantiate more than one processing instance at a time by seeing if it already exists + if(!checkIfProcessingExists(canvasID)){ + var canvas = document.getElementById(canvasID); + // datasrc and data-src are deprecated. + var processingSource = canvas.getAttribute('data-processing-sources'); + if (processingSource === null) { + // Temporary fallback for datasrc and data-src + processingSource = canvas.getAttribute('data-src'); + if (processingSource === null) { + processingSource = canvas.getAttribute('datasrc'); + } + } + if (processingSource) { + var filenames = processingSource.split(' '); + var code = ""; + for (var j = 0, fl = filenames.length; j < fl; j++) { + if (filenames[j]) { + var block = ajax(filenames[j]); + if (block !== false) { + code += ";\n" + block; + } + } + } + if(code!=""){ + Processing.addInstance(new Processing(canvas, code)); + }else{ + Processing.addInstance(new Processing(canvas, processingSource)); + } + } + }else{ + // purposefully void - A processing instance with the given id already exists + } +}; + /** + * Authors note: This should be added to the Popcorn library +* loadScript: adds a script to the DOM via. adding a