mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
51 lines
No EOL
1.3 KiB
HTML
51 lines
No EOL
1.3 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 amount = 180;
|
|
for (var i = 0; i < amount; i++) {
|
|
var path = new Path();
|
|
path.fillColor = new HSBColor(1, 1, Math.random());
|
|
path.strokeCap = 'round';
|
|
path.closed = true;
|
|
}
|
|
|
|
var position = view.center;
|
|
var mousePos = position;
|
|
var children = document.activeLayer.children;
|
|
var count = 0;
|
|
|
|
function iterate() {
|
|
count++;
|
|
var delta = (mousePos - position);
|
|
position += delta / 10;
|
|
for (var i = 1; i < amount; i++) {
|
|
var path = children[i];
|
|
var length = Math.abs(Math.sin(i + count / 20) * 300);
|
|
path.segments = [
|
|
position + delta / 1.5,
|
|
position + { angle: i * 2, length: length },
|
|
position + { angle: (i + 1) * 2, length: length }
|
|
];
|
|
path.fillColor.hue = count - length;
|
|
}
|
|
}
|
|
|
|
function onFrame() {
|
|
iterate();
|
|
}
|
|
|
|
function onMouseMove(event) {
|
|
iterate();
|
|
mousePos = event.point;
|
|
}
|
|
</script>
|
|
</head>
|
|
<body style='background-color:black'>
|
|
<canvas id="canvas" resize keepalive="true"></canvas>
|
|
</body> |