diff --git a/examples/Node.js/Tadpoles.js b/examples/Node.js/Tadpoles.js index 47ed04d6..6aad6cf8 100644 --- a/examples/Node.js/Tadpoles.js +++ b/examples/Node.js/Tadpoles.js @@ -1,7 +1,7 @@ -require('paper'); -var paper = require('./Tadpoles.pjs'); +var paper = require('paper'); +var scope = require('./Tadpoles.pjs')(new paper.Canvas(1024, 768)); -paper.view.exportFrames({ +scope.view.exportFrames({ amount: 400, directory: __dirname, onComplete: function() { diff --git a/examples/Node.js/Tadpoles.pjs b/examples/Node.js/Tadpoles.pjs index 6db5b820..3b02c84d 100644 --- a/examples/Node.js/Tadpoles.pjs +++ b/examples/Node.js/Tadpoles.pjs @@ -1,5 +1,3 @@ -paper.setup(new Canvas(1024, 768)); - // Adapted from Flocking Processing example by Daniel Schiffman: // http://processing.org/learning/topics/flocking.html diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index a11224b0..e87c8aef 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -404,15 +404,21 @@ var PaperScript = Base.exports.PaperScript = (function(root) { path = require('path'); require.extensions['.pjs'] = function(module, uri) { - var source = compile(fs.readFileSync(uri, 'utf8')), - scope = new PaperScope(); - scope.__filename = uri; - scope.__dirname = path.dirname(uri); - // Expose core methods and values - scope.require = require; - scope.console = console; - execute(source, scope); - module.exports = scope; + // Requiring a PaperScript on Node.js returns an initialize method which + // needs to receive a Canvas object when called and returns the + // PaperScope. + module.exports = function(canvas) { + var source = compile(fs.readFileSync(uri, 'utf8')), + scope = new PaperScope(); + scope.setup(canvas); + scope.__filename = uri; + scope.__dirname = path.dirname(uri); + // Expose core methods and values + scope.require = require; + scope.console = console; + execute(source, scope); + return scope; + }; }; /*#*/ } // __options.environment == 'node'