paper.js/examples/Animated/RoundedRectangles.html

48 lines
1.3 KiB
HTML
Raw Normal View History

2011-02-21 08:31:26 -05:00
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
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 mousePoint = document.bounds.center;
var amount = 25;
var colors = ['red', 'white', 'blue', 'white'];
for (var i = 0; i < amount; i++) {
var rect = new Rectangle([0, 0], [25, 25]);
rect.center = mousePoint;
var path = new Path.RoundRectangle(rect, 6);
path.fillColor = colors[i % 4];
var scale = (1 - i / amount) * 20;
path.scale(scale);
new PlacedSymbol(path);
}
// setInterval(draw, 30);
2011-03-04 06:38:38 -05:00
function onMouseDrag(event) {
mousePoint = event.point;
}
2011-03-04 06:38:38 -05:00
var children = document.activeLayer.children;
var count = 0;
function draw() {
count++;
for (var i = 0, l = children.length; i < l; i++) {
var item = children[i];
var delta = (mousePoint - item.position) / (i + 1);
item.rotate(Math.sin((count + i) / 10) * 7);
if (delta.length > 0.1)
item.translate(delta);
}
2011-03-04 06:38:38 -05:00
document.redraw();
Event.requestAnimationFrame(draw, document.canvas);
}
Event.requestAnimationFrame(draw, document.canvas);
</script>
</head>
<body>
<canvas id='canvas' width=1024 height=768></canvas>
</body>