1

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

1 回答 1

6

我已经完成了!代码应该以这种方式结束:

view.onFrame = function(event) { 
    for (var i = 0; i < len; i++) { 
        var item = project.activeLayer.children[i]; 
        item.rotate(3); 
    } 
} 
paper.view.draw();
于 2013-07-30T23:44:15.540 回答