paper.js/examples/Animated/AnimatedStar.html

52 lines
1.4 KiB
HTML
Raw Normal View History

2011-02-21 08:31:26 -05:00
<!DOCTYPE html>
2011-02-07 13:28:09 -05:00
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<link rel="stylesheet" href="../css/style.css">
2011-03-07 20:07:26 -05:00
<script type="text/javascript">var root = '../../'</script>
<script type="text/javascript" src="../../src/load.js"></script>
2011-03-04 06:38:38 -05:00
<script type="text/paperscript" canvas="canvas">
var layer = document.activeLayer;
var values = {
count: 34,
points: 32
};
2011-03-04 06:38:38 -05:00
var center = new Point(document.size) / 2;
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;
2011-05-05 19:19:24 -04:00
var vector = offset.normalize(l * (j % 2 ? 0.1 : -0.1));
2011-03-04 06:38:38 -05:00
path.add(offset + vector);
2011-02-20 17:28:38 -05:00
}
2011-03-04 06:38:38 -05:00
path.smooth();
var placedSymbol = new PlacedSymbol(path);
placedSymbol.position = center;
layer.appendBottom(placedSymbol);
}
2011-02-20 17:28:38 -05:00
function onFrame(event) {
2011-03-04 06:38:38 -05: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;
2011-03-04 06:38:38 -05:00
item.rotate(angle);
2011-02-07 13:28:09 -05:00
}
}
// Reposition the paths whenever the window is resized:
function onResize(event) {
document.activeLayer.position = event.size / 2;
}
2011-02-07 13:28:09 -05:00
</script>
</head>
<body>
<canvas id="canvas" resize keepalive="true"></canvas>
2011-02-07 13:28:09 -05:00
</body>