mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Add support for onFrameLoop() callback to PaperScript.
This commit is contained in:
parent
7e46eeabc4
commit
2fcca38a9c
2 changed files with 17 additions and 8 deletions
|
@ -33,20 +33,16 @@
|
||||||
placedSymbol.position = center;
|
placedSymbol.position = center;
|
||||||
layer.appendBottom(placedSymbol);
|
layer.appendBottom(placedSymbol);
|
||||||
}
|
}
|
||||||
// setInterval(draw, 30);
|
|
||||||
|
|
||||||
var count = 0;
|
var count = 0;
|
||||||
function draw() {
|
function onFrameLoop() {
|
||||||
count++;
|
count++;
|
||||||
for (var i = 0, l = layer.children.length; i < l; i++) {
|
for (var i = 0, l = layer.children.length; i < l; i++) {
|
||||||
var item = layer.children[i];
|
var item = layer.children[i];
|
||||||
var angle = (values.count - i) * Math.sin(count / 128) / 10;
|
var angle = (values.count - i) * Math.sin(count / 128) / 10;
|
||||||
item.rotate(angle);
|
item.rotate(angle);
|
||||||
}
|
}
|
||||||
document.redraw();
|
|
||||||
Event.requestAnimationFrame(draw, document.canvas);
|
|
||||||
}
|
}
|
||||||
Event.requestAnimationFrame(draw, document.canvas);
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -132,7 +132,8 @@ var PaperScript = new function() {
|
||||||
function run(code) {
|
function run(code) {
|
||||||
with (paper) {
|
with (paper) {
|
||||||
paper.tool = /onMouse(?:Up|Down|Move|Drag)/.test(code) && new Tool();
|
paper.tool = /onMouse(?:Up|Down|Move|Drag)/.test(code) && new Tool();
|
||||||
var res = eval(compile(code));
|
var res = eval(compile(code)),
|
||||||
|
doc = paper.document;
|
||||||
if (paper.tool) {
|
if (paper.tool) {
|
||||||
Base.each(['onEditOptions', 'onOptions', 'onSelect',
|
Base.each(['onEditOptions', 'onOptions', 'onSelect',
|
||||||
'onDeselect', 'onReselect', 'onMouseDown', 'onMouseUp',
|
'onDeselect', 'onReselect', 'onMouseDown', 'onMouseUp',
|
||||||
|
@ -143,9 +144,21 @@ var PaperScript = new function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
var onFrameLoop = eval('onFrameLoop');
|
||||||
|
if (onFrameLoop) {
|
||||||
|
function loop() {
|
||||||
|
onFrameLoop();
|
||||||
|
// Automatically redraw document each frame.
|
||||||
|
doc && doc.redraw();
|
||||||
|
Event.requestAnimationFrame(loop, doc && doc.canvas);
|
||||||
|
}
|
||||||
|
Event.requestAnimationFrame(loop, doc && doc.canvas);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
// Automatically redraw document at the end.
|
// Automatically redraw document at the end.
|
||||||
if (paper.document)
|
doc && doc.redraw();
|
||||||
paper.document.redraw();
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue