mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-07-02 16:00:23 -04:00
Get View#exportFrames() to work again on Node.js
This commit is contained in:
parent
e7c4e3c990
commit
85d60e199e
2 changed files with 9 additions and 11 deletions
|
@ -46,4 +46,4 @@ paper.view.onFrame = function(event) {
|
||||||
var angle = (values.count - i) * Math.sin(event.count / 128) / 10;
|
var angle = (values.count - i) * Math.sin(event.count / 128) / 10;
|
||||||
item.rotate(angle);
|
item.rotate(angle);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
|
@ -73,14 +73,13 @@ module.exports = function(paper) {
|
||||||
|
|
||||||
// Override requestAnimationFrame() to avoid setInterval() timers.
|
// Override requestAnimationFrame() to avoid setInterval() timers.
|
||||||
paper.DomEvent.requestAnimationFrame = function(callback) {
|
paper.DomEvent.requestAnimationFrame = function(callback) {
|
||||||
process.nextTick(callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Node.js based image exporting code.
|
// Node.js based image exporting code.
|
||||||
paper.CanvasView.inject({
|
paper.CanvasView.inject({
|
||||||
// DOCS: CanvasView#exportFrames(param);
|
// DOCS: CanvasView#exportFrames(param);
|
||||||
exportFrames: function(param) {
|
exportFrames: function(param) {
|
||||||
param = new paper.Base({
|
param = paper.Base.set({
|
||||||
fps: 30,
|
fps: 30,
|
||||||
prefix: 'frame-',
|
prefix: 'frame-',
|
||||||
amount: 1
|
amount: 1
|
||||||
|
@ -98,6 +97,12 @@ module.exports = function(paper) {
|
||||||
exportFrame(param);
|
exportFrame(param);
|
||||||
|
|
||||||
function exportFrame(param) {
|
function exportFrame(param) {
|
||||||
|
// Convert to a Base object, for #toString()
|
||||||
|
view.emit('frame', new paper.Base({
|
||||||
|
delta: frameDuration,
|
||||||
|
time: frameDuration * count,
|
||||||
|
count: count
|
||||||
|
}));
|
||||||
var file = path.join(param.directory,
|
var file = path.join(param.directory,
|
||||||
param.prefix + ('000000' + count).slice(-6) + '.png');
|
param.prefix + ('000000' + count).slice(-6) + '.png');
|
||||||
var out = view.exportImage(file, function() {
|
var out = view.exportImage(file, function() {
|
||||||
|
@ -114,7 +119,7 @@ module.exports = function(paper) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
lastTime = then;
|
lastTime = then;
|
||||||
if (count < param.amount) {
|
if (++count < param.amount) {
|
||||||
exportFrame(param);
|
exportFrame(param);
|
||||||
} else {
|
} else {
|
||||||
// Call onComplete handler when finished:
|
// Call onComplete handler when finished:
|
||||||
|
@ -123,13 +128,6 @@ module.exports = function(paper) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Convert to a Base object, for #toString()
|
|
||||||
view.emit('frame', new paper.Base({
|
|
||||||
delta: frameDuration,
|
|
||||||
time: frameDuration * count,
|
|
||||||
count: count
|
|
||||||
}));
|
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue