mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Change the way PaperScripts are executed in Node.js
Requiring a PaperScript returns an initialize method which receives the Canvas argument.
This commit is contained in:
parent
976b24b34c
commit
f97056e4b7
3 changed files with 18 additions and 14 deletions
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue