最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - paper.js onFrame method doesn't work - Stack Overflow

programmeradmin0浏览0评论

i'm trying to learn some paper.js, and its onFrame event doesn't work with me :( In code below i create 30 random shapes on canvas, and trying to rotate each one of them by onFrame method, but nothing is happening, paths stand fixed.

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();

i'm trying to learn some paper.js, and its onFrame event doesn't work with me :( In code below i create 30 random shapes on canvas, and trying to rotate each one of them by onFrame method, but nothing is happening, paths stand fixed.

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();
Share Improve this question edited Nov 5, 2013 at 16:13 JustBeingHelpful 19k39 gold badges168 silver badges251 bronze badges asked Jul 30, 2013 at 12:20 Alex KAlex K 1832 silver badges14 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

I've done with that! Code should be ended that way:

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

评论列表(0)

  1. 暂无评论