2011-03-19 20:11:06 -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>Curve Time Parameterization</title>
|
2011-05-05 11:25:17 -04:00
|
|
|
<link rel="stylesheet" href="../css/style.css">
|
2011-06-12 14:03:18 -04:00
|
|
|
<script type="text/javascript" src="../../dist/paper.js"></script>
|
2011-03-19 20:11:06 -04:00
|
|
|
<script type="text/paperscript" canvas="canvas">
|
|
|
|
var path = new Path();
|
|
|
|
path.moveTo(200, 200);
|
|
|
|
path.curveTo([170, 50], [300, 200]);
|
|
|
|
path.strokeWidth = 1;
|
|
|
|
path.strokeColor = 'black';
|
|
|
|
var curve = path.curves[0];
|
2011-03-20 07:41:58 -04:00
|
|
|
|
2011-03-19 20:11:06 -04:00
|
|
|
function onMouseMove(event) {
|
2011-04-26 07:31:35 -04:00
|
|
|
modifyCurve(event.point, true);
|
2011-03-20 07:41:58 -04:00
|
|
|
}
|
|
|
|
|
2011-04-26 07:31:35 -04:00
|
|
|
function modifyCurve(point, remove) {
|
2011-03-20 07:41:58 -04:00
|
|
|
curve.segment2.point = point;
|
2011-03-19 20:11:06 -04:00
|
|
|
var length = curve.length;
|
|
|
|
var step = 10;
|
2011-04-26 07:31:35 -04:00
|
|
|
var iteratively = false;
|
2011-06-20 13:17:07 -04:00
|
|
|
var flatten = true;
|
2011-03-20 07:41:58 -04:00
|
|
|
var num = Math.floor(length / step);
|
|
|
|
var prev = 0;
|
2011-06-20 13:17:07 -04:00
|
|
|
if (flatten) {
|
2011-06-05 08:22:06 -04:00
|
|
|
var clone = path.clone();
|
2011-06-20 13:17:07 -04:00
|
|
|
clone.flatten(step);
|
2011-06-05 08:22:06 -04:00
|
|
|
for (var i = 0; i < clone.segments.length; i++) {
|
|
|
|
var point = clone.segments[i].point;
|
|
|
|
var circle = new Path.Circle(point, step / 2);
|
|
|
|
circle.strokeColor = 'red';
|
|
|
|
if (remove)
|
|
|
|
circle.removeOnMove();
|
|
|
|
}
|
|
|
|
clone.remove();
|
|
|
|
} else {
|
|
|
|
for (var i = 0, pos = 0; i <= num; i++, pos += step) {
|
|
|
|
var t = iteratively
|
2011-07-06 17:13:38 -04:00
|
|
|
? curve.getParameterAt(step, prev)
|
|
|
|
: curve.getParameterAt(pos);
|
2013-01-28 19:30:28 -05:00
|
|
|
var point = curve.getPointAt(t, true);
|
2011-06-05 08:22:06 -04:00
|
|
|
var circle = new Path.Circle(point, step / 2);
|
|
|
|
circle.strokeColor = 'red';
|
|
|
|
if (remove)
|
|
|
|
circle.removeOnMove();
|
|
|
|
prev = t;
|
|
|
|
}
|
2011-03-19 20:11:06 -04:00
|
|
|
}
|
|
|
|
}
|
2011-03-20 07:41:58 -04:00
|
|
|
|
2011-04-26 07:31:35 -04:00
|
|
|
// modifyCurve(new Point(400, 377), false);
|
2011-03-20 07:41:58 -04:00
|
|
|
|
2011-03-19 20:11:06 -04:00
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
2011-06-29 07:44:06 -04:00
|
|
|
<canvas id="canvas" resize></canvas>
|
2011-05-30 18:27:39 -04:00
|
|
|
</body>
|
|
|
|
</html>
|