You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.5 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Path Structure</title>
  6. <link rel="stylesheet" href="../css/style.css">
  7. <script type="text/javascript" src="../../dist/paper-full.js"></script>
  8. <script type="text/paperscript" canvas="canvas">
  9. var y = view.size.height / 2;
  10. var width = view.size.width;
  11. var vector = new Point({
  12. angle: 45,
  13. length: width / 5
  14. });
  15. var offset = width / 30;
  16. var handleTexts = [];
  17. var path = new Path({
  18. segments: [
  19. [[offset, y], null, vector.rotate(-90)],
  20. [[width / 2, y], vector.rotate(-180), vector],
  21. [[width - offset, y], vector.rotate(90), null]
  22. ],
  23. fullySelected: true
  24. });
  25. function onMouseMove(event) {
  26. var point = event.point.clone();
  27. // Constrain the event point, to not cut off the text:
  28. if (point.y < 22)
  29. point.y = 22;
  30. if (point.y > view.size.height - 24)
  31. point.y = view.size.height - 24;
  32. var delta = point - view.center;
  33. for (var i = 0; i < 2; i++) {
  34. var curve = path.curves[i];
  35. curve.handle1.y = curve.handle2.y = delta.y * (i % 2 ? 1 : -1);
  36. var firstPoint = curve.point1 + curve.handle1;
  37. var secondPoint = curve.point2 + curve.handle2;
  38. handleTexts[i * 2].point = secondPoint -
  39. (firstPoint.y < y ? [0, 10] : [0, -18]);
  40. handleTexts[i * 2 + 1].point = firstPoint -
  41. (firstPoint.y < y ? [0, 10] : [0, -18]);
  42. }
  43. }
  44. project.currentStyle.fillColor = 'black';
  45. for (var i = 0; i < 3; i++) {
  46. var segment = path.segments[i];
  47. var text = new PointText({
  48. point: segment.point - [0, 10],
  49. content: i,
  50. fontSize: 12,
  51. justification: 'center'
  52. });
  53. }
  54. for (var i = 0; i < 2; i++) {
  55. var handleInText = new PointText({
  56. content: 'handleIn',
  57. fontSize: 12,
  58. justification: 'center'
  59. });
  60. handleTexts.push(handleInText);
  61. var handleOutText = new PointText({
  62. content: 'handleOut',
  63. fontSize: 12,
  64. justification: 'center'
  65. });
  66. handleTexts.push(handleOutText);
  67. }
  68. // Call onMouseMove once to correctly position the text items:
  69. onMouseMove({
  70. point: view.center + vector.rotate(-90)
  71. });
  72. </script>
  73. </head>
  74. <body>
  75. <canvas id='canvas' resize></canvas>
  76. </body>
  77. </html>