Web UI for ARGUS server
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.

76 lines
2.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Square Rounded</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. /////////////////////////////////////////////////////////////////////
  10. // Values
  11. var values = {
  12. radius: 10,
  13. tolerance: 5
  14. };
  15. checkValues();
  16. /////////////////////////////////////////////////////////////////////
  17. // Mouse handling
  18. var handle;
  19. function checkValues() {
  20. var min = values.radius * 2;
  21. if (values.tolerance < min) values.tolerance = min;
  22. handle = values.radius * Numerical.KAPPA;
  23. }
  24. var path;
  25. function onMouseDown(event) {
  26. path = new Path({
  27. segments: [event.point, event.point],
  28. strokeColor: 'black',
  29. strokeWidth: 5,
  30. strokeCap: 'round'
  31. });
  32. prevPoint = path.firstSegment.point;
  33. curPoint = path.lastSegment.point;
  34. curHandleSeg = null;
  35. }
  36. var curPoint, prevPoint, curHandleSeg;
  37. function onMouseDrag(event) {
  38. var point = event.point;
  39. var diff = (point - prevPoint).abs();
  40. if (diff.x < diff.y) {
  41. curPoint.x = prevPoint.x;
  42. curPoint.y = point.y;
  43. } else {
  44. curPoint.x = point.x;
  45. curPoint.y = prevPoint.y;
  46. }
  47. var normal = curPoint - prevPoint;
  48. normal.length = 1;
  49. if (curHandleSeg) {
  50. curHandleSeg.point = prevPoint + (normal * values.radius);
  51. curHandleSeg.handleIn = normal * -handle;
  52. }
  53. var minDiff = Math.min(diff.x, diff.y);
  54. if (minDiff > values.tolerance) {
  55. var point = curPoint - (normal * values.radius);
  56. var segment = new Segment(point, null, normal * handle);
  57. path.insert(path.segments.length - 1, segment);
  58. curHandleSeg = path.lastSegment;
  59. // clone as we want the unmodified one:
  60. prevPoint = curHandleSeg.point.clone();
  61. path.add(curHandleSeg);
  62. curPoint = path.lastSegment.point;
  63. }
  64. }
  65. </script>
  66. </head>
  67. <body>
  68. <canvas id="canvas" resize></canvas>
  69. </body>
  70. </html>