mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -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('paper');
|
||||||
var paper = require('./Tadpoles.pjs');
|
var scope = require('./Tadpoles.pjs')(new paper.Canvas(1024, 768));
|
||||||
|
|
||||||
paper.view.exportFrames({
|
scope.view.exportFrames({
|
||||||
amount: 400,
|
amount: 400,
|
||||||
directory: __dirname,
|
directory: __dirname,
|
||||||
onComplete: function() {
|
onComplete: function() {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
paper.setup(new Canvas(1024, 768));
|
|
||||||
|
|
||||||
// Adapted from Flocking Processing example by Daniel Schiffman:
|
// Adapted from Flocking Processing example by Daniel Schiffman:
|
||||||
// http://processing.org/learning/topics/flocking.html
|
// http://processing.org/learning/topics/flocking.html
|
||||||
|
|
||||||
|
|
|
@ -404,15 +404,21 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
|
||||||
path = require('path');
|
path = require('path');
|
||||||
|
|
||||||
require.extensions['.pjs'] = function(module, uri) {
|
require.extensions['.pjs'] = function(module, uri) {
|
||||||
var source = compile(fs.readFileSync(uri, 'utf8')),
|
// Requiring a PaperScript on Node.js returns an initialize method which
|
||||||
scope = new PaperScope();
|
// needs to receive a Canvas object when called and returns the
|
||||||
scope.__filename = uri;
|
// PaperScope.
|
||||||
scope.__dirname = path.dirname(uri);
|
module.exports = function(canvas) {
|
||||||
// Expose core methods and values
|
var source = compile(fs.readFileSync(uri, 'utf8')),
|
||||||
scope.require = require;
|
scope = new PaperScope();
|
||||||
scope.console = console;
|
scope.setup(canvas);
|
||||||
execute(source, scope);
|
scope.__filename = uri;
|
||||||
module.exports = scope;
|
scope.__dirname = path.dirname(uri);
|
||||||
|
// Expose core methods and values
|
||||||
|
scope.require = require;
|
||||||
|
scope.console = console;
|
||||||
|
execute(source, scope);
|
||||||
|
return scope;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/*#*/ } // __options.environment == 'node'
|
/*#*/ } // __options.environment == 'node'
|
||||||
|
|
Loading…
Reference in a new issue