2011-04-23 09:47:28 -04:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2013-06-02 16:41:10 -04:00
|
|
|
<meta charset="UTF-8">
|
2011-06-30 09:57:17 -04:00
|
|
|
<title>Smoothing</title>
|
2011-05-05 11:25:17 -04:00
|
|
|
<link rel="stylesheet" href="../css/style.css">
|
2014-04-06 07:44:19 -04:00
|
|
|
<script type="text/javascript" src="../../dist/paper-full.js"></script>
|
2011-04-23 09:47:28 -04:00
|
|
|
<script type="text/paperscript" canvas="canvas">
|
2011-05-08 14:14:22 -04:00
|
|
|
var width, height, center;
|
2011-04-23 09:47:28 -04:00
|
|
|
var points = 10;
|
|
|
|
var smooth = true;
|
2013-03-02 14:59:27 -05:00
|
|
|
var path = new Path({
|
|
|
|
fillColor: 'black'
|
|
|
|
});
|
2011-05-16 07:51:20 -04:00
|
|
|
var mousePos = view.center / 2;
|
2011-05-08 14:14:22 -04:00
|
|
|
var pathHeight = mousePos.y;
|
2011-05-05 13:40:10 -04:00
|
|
|
initializePath();
|
2011-05-08 14:14:22 -04:00
|
|
|
|
2011-05-05 13:40:10 -04:00
|
|
|
function initializePath() {
|
2011-05-16 07:51:20 -04:00
|
|
|
center = view.center;
|
|
|
|
width = view.size.width;
|
|
|
|
height = view.size.height / 2;
|
2011-05-05 13:40:10 -04:00
|
|
|
path.segments = [];
|
2011-05-16 07:51:20 -04:00
|
|
|
path.add(view.bounds.bottomLeft);
|
2011-05-05 13:40:10 -04:00
|
|
|
for (var i = 1; i < points; i++) {
|
|
|
|
var point = new Point(width / points * i, center.y);
|
|
|
|
path.add(point);
|
|
|
|
}
|
2011-05-16 07:51:20 -04:00
|
|
|
path.add(view.bounds.bottomRight);
|
2011-06-20 11:40:30 -04:00
|
|
|
path.fullySelected = true;
|
2011-04-23 09:47:28 -04:00
|
|
|
}
|
2011-05-08 14:14:22 -04:00
|
|
|
|
2011-05-15 13:12:56 -04:00
|
|
|
function onFrame(event) {
|
2011-05-08 14:14:22 -04:00
|
|
|
pathHeight += (center.y - mousePos.y - pathHeight) / 10;
|
2011-04-23 10:23:31 -04:00
|
|
|
for (var i = 1; i < points; i++) {
|
2011-05-15 13:12:56 -04:00
|
|
|
var sinSeed = event.count + (i + i % 10) * 100;
|
2011-04-23 09:47:28 -04:00
|
|
|
var sinHeight = Math.sin(sinSeed / 200) * pathHeight;
|
|
|
|
var yPos = Math.sin(sinSeed / 100) * sinHeight + height;
|
|
|
|
path.segments[i].point.y = yPos;
|
|
|
|
}
|
|
|
|
if (smooth)
|
|
|
|
path.smooth();
|
|
|
|
}
|
2011-05-08 14:14:22 -04:00
|
|
|
|
2011-04-23 09:47:28 -04:00
|
|
|
function onMouseMove(event) {
|
2011-05-08 14:14:22 -04:00
|
|
|
mousePos = event.point;
|
2011-04-23 09:47:28 -04:00
|
|
|
}
|
2011-05-08 14:14:22 -04:00
|
|
|
|
2011-04-23 09:47:28 -04:00
|
|
|
function onMouseDown(event) {
|
|
|
|
smooth = !smooth;
|
|
|
|
if (!smooth) {
|
|
|
|
// If smooth has been turned off, we need to reset
|
|
|
|
// the handles of the path:
|
2011-04-23 10:23:31 -04:00
|
|
|
for (var i = 0, l = path.segments.length; i < l; i++) {
|
2011-04-23 09:47:28 -04:00
|
|
|
var segment = path.segments[i];
|
|
|
|
segment.handleIn = segment.handleOut = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-08 14:14:22 -04:00
|
|
|
|
2011-05-05 13:40:10 -04:00
|
|
|
// Reposition the path whenever the window is resized:
|
2011-05-16 07:51:20 -04:00
|
|
|
function onResize(event) {
|
|
|
|
initializePath();
|
|
|
|
}
|
2011-04-23 09:47:28 -04:00
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
2011-06-29 07:44:06 -04:00
|
|
|
<canvas id="canvas" resize></canvas>
|
2011-05-30 18:13:25 -04:00
|
|
|
</body>
|
2014-04-06 07:44:19 -04:00
|
|
|
</html>
|