mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
96 lines
No EOL
2.5 KiB
HTML
96 lines
No EOL
2.5 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" src="../../dist/paper.js"></script>
|
|
<script type="text/paperscript" canvas="canvas">
|
|
var i, text, handleInText, handleOutText, y
|
|
segmentTexts = [],
|
|
handleTexts = [],
|
|
path = new Path();
|
|
|
|
path.fullySelected = true;
|
|
|
|
function onMouseMove(event) {
|
|
var delta, i, curve, firstPoint, secondPoint,
|
|
point = event.point.clone();
|
|
// Constrain the event point, to not cut off the text:
|
|
if (point.y < 22) {
|
|
point.y = 22;
|
|
}
|
|
if (point.y > view.size.height - 24) {
|
|
point.y = view.size.height - 24;
|
|
}
|
|
delta = point - view.center;
|
|
for (i = 0; i < path.segments.length; i++) {
|
|
segmentTexts[i].point = path.segments[i].point - [0, 10];
|
|
}
|
|
for (i = 0; i < path.curves.length; i++) {
|
|
curve = path.curves[i];
|
|
curve.handle1.y = curve.handle2.y = delta.y * (i % 2 ? 1 : -1);
|
|
firstPoint = curve.point1 + curve.handle1;
|
|
secondPoint = curve.point2 + curve.handle2;
|
|
handleTexts[i * 2].point = secondPoint -
|
|
(firstPoint.y < y ? [0, 10] : [0, -18]);
|
|
handleTexts[i * 2 + 1].point = firstPoint -
|
|
(firstPoint.y < y ? [0, 10] : [0, -18]);
|
|
}
|
|
}
|
|
|
|
function onResize(event) {
|
|
var width = view.size.width,
|
|
offset = width / 30,
|
|
vector = new Point({
|
|
angle: 45,
|
|
length: width / 5
|
|
});
|
|
y = view.size.height / 2;
|
|
path.segments = [
|
|
[[offset, y], null, vector.rotate(-90)],
|
|
[[width / 2, y], vector.rotate(-180), vector],
|
|
[[width - offset, y], vector.rotate(90), null]
|
|
];
|
|
onMouseMove({
|
|
point: new Point(event.size.width, event.size.height - 24)
|
|
});
|
|
}
|
|
|
|
project.currentStyle.fillColor = 'black';
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
text = new PointText();
|
|
text.content = '' + i;
|
|
text.justification = 'center';
|
|
text.fontSize = 9;
|
|
segmentTexts.push(text);
|
|
}
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
handleInText = new PointText();
|
|
handleInText.content = 'handleIn';
|
|
handleInText.justification = 'center';
|
|
handleInText.fontSize = 9;
|
|
handleTexts.push(handleInText);
|
|
|
|
handleOutText = new PointText();
|
|
handleOutText.content = 'handleOut';
|
|
handleOutText.justification = 'center';
|
|
handleOutText.fontSize = 9;
|
|
handleTexts.push(handleOutText);
|
|
}
|
|
|
|
// Call onResize once to correctly position everything
|
|
onResize({
|
|
size: {
|
|
width: view.size.width,
|
|
height: view.size.height * 2 / 3
|
|
}
|
|
});
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<canvas id='canvas' width=303 height=167 resize></canvas>
|
|
</body>
|
|
</html> |