paper.js/examples/Animated/AnimatedStar.html
2011-05-16 13:42:23 +01:00

51 lines
No EOL
1.4 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript">var root = '../../'</script>
<script type="text/javascript" src="../../src/load.js"></script>
<script type="text/paperscript" canvas="canvas">
var layer = project.activeLayer;
var values = {
count: 34,
points: 32
};
for (var i = 0; i < values.count; i++) {
var offset = new Point(20 + 10 * i, 0);
var path = new Path();
path.fillColor = i % 2 ? 'red' : 'black';
path.closed = true;
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 + vector);
}
path.smooth();
var placedSymbol = new PlacedSymbol(path);
placedSymbol.position = view.center;
layer.appendBottom(placedSymbol);
}
function onFrame(event) {
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);
}
}
// Reposition the paths whenever the window is resized:
function onResize(event) {
project.activeLayer.position = view.center;
}
</script>
</head>
<body>
<canvas id="canvas" resize keepalive="true"></canvas>
</body>