mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-07-11 12:14:02 -04:00
Clean up PathStructure example.
This commit is contained in:
parent
fb2a05f989
commit
3ddf2b40ca
1 changed files with 56 additions and 67 deletions
|
@ -6,16 +6,56 @@
|
||||||
<link rel="stylesheet" href="../css/style.css">
|
<link rel="stylesheet" href="../css/style.css">
|
||||||
<script type="text/javascript" src="../../dist/paper.js"></script>
|
<script type="text/javascript" src="../../dist/paper.js"></script>
|
||||||
<script type="text/paperscript" canvas="canvas">
|
<script type="text/paperscript" canvas="canvas">
|
||||||
var i, text, handleInText, handleOutText, y
|
var yMiddle;
|
||||||
segmentTexts = [],
|
var segmentTexts = [];
|
||||||
handleTexts = [],
|
var handleTexts = [];
|
||||||
path = new Path();
|
|
||||||
|
|
||||||
|
var path = new Path();
|
||||||
path.fullySelected = true;
|
path.fullySelected = true;
|
||||||
|
|
||||||
|
for (var i = 0; i < 3; i++) {
|
||||||
|
var text = new PointText();
|
||||||
|
text.content = '' + i;
|
||||||
|
text.justification = 'center';
|
||||||
|
text.fontSize = 9;
|
||||||
|
segmentTexts.push(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < 2; i++) {
|
||||||
|
var handleInText = new PointText();
|
||||||
|
handleInText.content = 'handleIn';
|
||||||
|
handleInText.justification = 'center';
|
||||||
|
handleInText.fontSize = 9;
|
||||||
|
handleTexts.push(handleInText);
|
||||||
|
|
||||||
|
var handleOutText = handleInText.clone();
|
||||||
|
handleOutText.content = 'handleOut';
|
||||||
|
handleTexts.push(handleOutText);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call onResize directly on execution to correctly position everything
|
||||||
|
onResize();
|
||||||
|
|
||||||
|
function onResize() {
|
||||||
|
var width = view.size.width;
|
||||||
|
var offset = width / 30;
|
||||||
|
var vector = new Point({
|
||||||
|
angle: 45,
|
||||||
|
length: width / 5
|
||||||
|
});
|
||||||
|
yMiddle = view.size.height / 2;
|
||||||
|
path.segments = [
|
||||||
|
[[offset, yMiddle], null, vector.rotate(-90)],
|
||||||
|
[[width / 2, yMiddle], vector.rotate(-180), vector],
|
||||||
|
[[width - offset, yMiddle], vector.rotate(90), null]
|
||||||
|
];
|
||||||
|
onMouseMove({
|
||||||
|
point: view.bounds.bottomRight
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function onMouseMove(event) {
|
function onMouseMove(event) {
|
||||||
var delta, i, curve, firstPoint, secondPoint,
|
var point = event.point.clone();
|
||||||
point = event.point.clone();
|
|
||||||
// Constrain the event point, to not cut off the text:
|
// Constrain the event point, to not cut off the text:
|
||||||
if (point.y < 22) {
|
if (point.y < 22) {
|
||||||
point.y = 22;
|
point.y = 22;
|
||||||
|
@ -23,74 +63,23 @@
|
||||||
if (point.y > view.size.height - 24) {
|
if (point.y > view.size.height - 24) {
|
||||||
point.y = view.size.height - 24;
|
point.y = view.size.height - 24;
|
||||||
}
|
}
|
||||||
delta = point - view.center;
|
var delta = point - view.center;
|
||||||
for (i = 0; i < path.segments.length; i++) {
|
for (var i = 0; i < path.segments.length; i++) {
|
||||||
segmentTexts[i].point = path.segments[i].point - [0, 10];
|
segmentTexts[i].point = path.segments[i].point - [0, 10];
|
||||||
}
|
}
|
||||||
for (i = 0; i < path.curves.length; i++) {
|
for (var i = 0; i < path.curves.length; i++) {
|
||||||
curve = path.curves[i];
|
var curve = path.curves[i];
|
||||||
curve.handle1.y = curve.handle2.y = delta.y * (i % 2 ? 1 : -1);
|
curve.handle1.y = curve.handle2.y = delta.y * (i % 2 ? 1 : -1);
|
||||||
firstPoint = curve.point1 + curve.handle1;
|
var firstPoint = curve.point1 + curve.handle1;
|
||||||
secondPoint = curve.point2 + curve.handle2;
|
var secondPoint = curve.point2 + curve.handle2;
|
||||||
handleTexts[i * 2].point = secondPoint -
|
var offset = (firstPoint.y < yMiddle ? [0, 10] : [0, -18]);
|
||||||
(firstPoint.y < y ? [0, 10] : [0, -18]);
|
handleTexts[i * 2].point = secondPoint - offset;
|
||||||
handleTexts[i * 2 + 1].point = firstPoint -
|
handleTexts[i * 2 + 1].point = firstPoint - offset;
|
||||||
(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>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<canvas id='canvas' width=303 height=167 resize></canvas>
|
<canvas id='canvas' resize></canvas>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue