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