paper.js/examples/Animated/animatedStar.html
2011-02-16 22:35:17 +01:00

60 lines
No EOL
2.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script type="text/javascript" src="../../lib/Bootstrap.js"></script>
<script type="text/javascript" src="../../src/Paper.js"></script>
<script type="text/javascript" src="../../src/tool/ToolEvent.js"></script>
<script type="text/javascript" src="../../src/tool/ToolHandler.js"></script>
<script type="text/javascript" src="../../src/tool/Tool.js"></script>
<script type="text/javascript" src="../../src/basic/Point.js"></script>
<script type="text/javascript" src="../../src/basic/Rectangle.js"></script>
<script type="text/javascript" src="../../src/basic/Size.js"></script>
<script type="text/javascript" src="../../src/basic/Matrix.js"></script>
<script type="text/javascript" src="../../src/document/Doc.js"></script>
<script type="text/javascript" src="../../src/item/Item.js"></script>
<script type="text/javascript" src="../../src/item/Group.js"></script>
<script type="text/javascript" src="../../src/item/Layer.js"></script>
<script type="text/javascript" src="../../src/item/PathStyle.js"></script>
<script type="text/javascript" src="../../src/path/Segment.js"></script>
<script type="text/javascript" src="../../src/path/PathItem.js"></script>
<script type="text/javascript" src="../../src/path/Path.js"></script>
<script>
var canvas, doc;
var count = 0;
window.onload = function() {
canvas = document.getElementById('canvas');
doc = new Doc(canvas);
console.log(doc.currentStyle);
doc.currentStyle.fillColor = 'black';
setInterval(draw, 60);
}
function draw() {
count++;
doc.activeLayer.children = [];
var point = new Point(1024, 768).divide(2);
for (var i = 0; i < 35; i++) {
var vector = new Point(20 + 10 * i, 0).rotate(i * (360 / 35 * 2) * Math.sin(count / 150));
var l = vector.length;
var path = new Path();
// path.strokeColor = '#000000';
//path.fillColor = i % 2 ? 'red' : 'black';
path.closed = true;
for (var j = 0; j < 32; j++) {
vector = vector.rotate(45 / 4);
var newPoint = point.add(vector).add(vector.rotate(-180).normalize(l * (j % 2 ? 0.1 : -0.1)));
path.add(newPoint);
}
path.smooth();
}
doc.activeLayer.children.reverse();
doc.redraw();
}
</script>
</head>
<body>
<canvas id='canvas' width=1024 height=768></canvas>
</body>