From 5414a43ab5107322660756375c4cc36dd7064f27 Mon Sep 17 00:00:00 2001 From: kroko Date: Fri, 16 May 2014 19:22:27 +0300 Subject: [PATCH 1/4] correction for the relative path to load processing.js in lib --- lib/processing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/processing.js b/lib/processing.js index bad7a5f..4afed1c 100644 --- a/lib/processing.js +++ b/lib/processing.js @@ -16,7 +16,7 @@ var fs = require('fs') , navigator = window.navigator , HTMLImageElement = window.HTMLImageElement , noop = function() {} - , processing = fs.readFileSync('./deps/processing-js/processing.js'); + , processing = fs.readFileSync(__dirname+'/../deps/processing-js/processing.js'); /** * Expose `version`. From 974a286d9db85254dd8a697be9c3ef259aa934b1 Mon Sep 17 00:00:00 2001 From: kroko Date: Fri, 16 May 2014 19:56:15 +0300 Subject: [PATCH 2/4] referenced the submodule to the newest processingjs (1.4.8) --- deps/processing-js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/processing-js b/deps/processing-js index 308591d..2c88a18 160000 --- a/deps/processing-js +++ b/deps/processing-js @@ -1 +1 @@ -Subproject commit 308591d05db8be7e9a6ea0ea1f9ca1fb304e4e89 +Subproject commit 2c88a18fcd10951bd84008a5c2ebd996fe873042 From ddcb76dc12199559c0aecf8e1d99823dbbe3b780 Mon Sep 17 00:00:00 2001 From: kroko Date: Fri, 16 May 2014 21:35:18 +0300 Subject: [PATCH 3/4] reflect changes between upgrade from 1.4.1 to 1.4.8, this breaks nulltask example --- lib/processing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/processing.js b/lib/processing.js index 4afed1c..c30e22b 100644 --- a/lib/processing.js +++ b/lib/processing.js @@ -57,7 +57,7 @@ eval('(function(window, document) {' * Expose `Processing`. */ -exports.Processing = Processing; +exports.Processing = window.Processing; /** * Return processing instance. From ed0e00937d9aedfc0e44bd0e462f33d37ff26908 Mon Sep 17 00:00:00 2001 From: kroko Date: Fri, 16 May 2014 21:39:53 +0300 Subject: [PATCH 4/4] added compile example, that could be incorporated into Grunt webapp pack-and-go workflow --- Readme.md | 39 +++++++++++++++++++++++++++++++++++++ examples/compile/compile.js | 33 +++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 examples/compile/compile.js diff --git a/Readme.md b/Readme.md index dbb17ee..e653a4c 100644 --- a/Readme.md +++ b/Readme.md @@ -27,6 +27,45 @@ fs.readFile(sketch, function(err, data) { }); ``` +## Usage + +```javascript +// Compile processing code into javascript, so it can be used in a LAMP webapp more effectively (no p5 lang parsing step by client needed) +// Intended to use with Grunt when developing and deploying web applications +// contribution by kroko.me + +var fs = require('fs'); +var p5 = require('processing'); +if (process.argv.length != 5) { + console.log("Usage: node compile.js "); + process.exit(code = 1); +} +else { + console.log("Reading file: " + process.argv[2]); + console.log("Output will be: " + process.argv[3]); + console.log("Variable will be: " + process.argv[4]); +} +console.log("Compiling sketch..."); + +fs.readFile(process.argv[2], function(err, data) { + var compiled = p5.Processing.compile(data.toString('utf-8')); + compiled = "var " + process.argv[4] + " = " + compiled + ";"; + fs.writeFile(process.argv[3], compiled, function(err) { + if (err) { + console.log(err); + } else { + console.log("...done!"); + } + }); +}); + +// Usage in web +// var domCanvas = document.getElementById('id-of-canvas-dom-element'); +// pjsPtr = new Processing(domCanvas, valiable-name-as-passed-to-this-script); +// if (pjsPtr) { } +``` + + ## Authors - Seiya Konno <seiya@uniba.jp> ([nulltask](https://github.com/nulltask)) diff --git a/examples/compile/compile.js b/examples/compile/compile.js new file mode 100644 index 0000000..ce1c83a --- /dev/null +++ b/examples/compile/compile.js @@ -0,0 +1,33 @@ +// Compile processing code into javascript, so that can be used in webpage more effectively (no p5 lang parsing step by client needed) +// Intended to use with Grunt when developing and deploying web applications +// contribution by kroko.me + +var fs = require('fs'); +var p5 = require('processing'); +if (process.argv.length != 5) { + console.log("Usage: node compile.js "); + process.exit(code = 1); +} +else { + console.log("Reading file: " + process.argv[2]); + console.log("Output will be: " + process.argv[3]); + console.log("Variable will be: " + process.argv[4]); +} +console.log("Compiling sketch..."); + +fs.readFile(process.argv[2], function(err, data) { + var compiled = p5.Processing.compile(data.toString('utf-8')); + compiled = "var " + process.argv[4] + " = " + compiled + ";"; + fs.writeFile(process.argv[3], compiled, function(err) { + if (err) { + console.log(err); + } else { + console.log("...done!"); + } + }); +}); + +// Usage in web +// var domCanvas = document.getElementById('id_of_canvas_dom_element'); +// pjsPtr = new Processing(domCanvas, valiable_name_as_passed_to_this_script); +// if (pjsPtr) { } \ No newline at end of file