gpt4 book ai didi

javascript - paper.js onFrame 方法不起作用

转载 作者:行者123 更新时间:2023-11-30 08:50:58 25 4
gpt4 key购买 nike

我正在尝试学习一些 paper.js , 及其 onFrame event对我不起作用:(在下面的代码中,我在 Canvas 上创建了 30 个随机形状,并尝试通过 onFrame 方法旋转每个形状,但没有任何反应,路径保持不变。

var len = 30;
var array = new Array();
var rand;
var colors = ['#fbff00', '#99ff37', '#00eeff', '#374afe', '#ff005e'];
for(var i = 0; i < len; i++) {
rand = getRandom(0, 4);
switch (rand) {
case 0: // if 0, create circle
var path = new Path.Circle({
center: [getRandom(30, scrwidth - 30), getRandom(30, scrheight - 30)],
radius: 30
});
path.fillColor = colors[getRandom(0, 4)];
array.push(path);
break;
//and some others in the same way
}
}
function getRandom(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function onFrame(event) {
for (var i = 0; i < len; i++) {
var item = project.activeLayer.children[i];
item.rotate(3);
}
}
paper.view.draw();

最佳答案

我已经完成了!代码应该这样结束:

view.onFrame = function(event) { 
for (var i = 0; i < len; i++) {
var item = project.activeLayer.children[i];
item.rotate(3);
}
}
paper.view.draw();

关于javascript - paper.js onFrame 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17946891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com