paper.js/examples/Node.js/AnimatedStar.js

53 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

// Please note: When loading paper as a normal module installed in node_modules,
// you would use this instead:
// var paper = require('paper-jsdom-canvas');
var paper = require('../../dist/paper-core.js');
paper.setup(new paper.Size(1024, 768));
2011-08-10 15:04:01 -04:00
var layer = paper.project.activeLayer;
var values = {
2014-08-16 13:24:54 -04:00
count: 34,
points: 32
2011-08-10 15:04:01 -04:00
};
initialize();
paper.view.exportFrames({
2014-08-16 13:24:54 -04:00
amount: 100,
directory: __dirname,
onComplete: function() {
console.log('Done exporting.');
},
onProgress: function(event) {
console.log(event.percentage + '% complete, frame took: ' + event.delta);
}
2011-08-10 15:04:01 -04:00
});
function initialize() {
2014-08-16 13:24:54 -04:00
for (var i = 0; i < values.count; i++) {
var offset = new paper.Point(20 + 10 * i, 0);
var path = new paper.Path();
path.fillColor = i % 2 ? 'red' : 'black';
path.closed = true;
2011-08-10 15:04:01 -04:00
2014-08-16 13:24:54 -04:00
var l = offset.length;
for (var j = 0; j < values.points * 2; j++) {
offset.angle += 360 / values.points;
var vector = offset.normalize(l * (j % 2 ? 0.1 : -0.1));
path.add(offset.add(vector));
}
path.smooth();
layer.insertChild(0, path);
}
layer.fitBounds(paper.view.bounds);
2011-08-10 15:04:01 -04:00
}
paper.view.onFrame = function(event) {
2014-08-16 13:24:54 -04:00
for (var i = 0, l = layer.children.length; i < l; i++) {
var item = layer.children[i];
var angle = (values.count - i) * Math.sin(event.count / 128) / 10;
item.rotate(angle);
}
};