Web Interface For Lite Argus Control modules
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.

95 lines
3.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Path Editing</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 values = {
  10. paths: 100,
  11. minPoints: 5,
  12. maxPoints: 15,
  13. minRadius: 30,
  14. maxRadius: 90
  15. };
  16. var hitOptions = {
  17. segments: true,
  18. stroke: true,
  19. fill: true,
  20. tolerance: 5
  21. };
  22. var radiusDelta = values.maxRadius - values.minRadius;
  23. var pointsDelta = values.maxPoints - values.minPoints;
  24. for (var i = 0; i < values.paths; i++) {
  25. var radius = values.minRadius + Math.random() * radiusDelta;
  26. var points = values.minPoints + Math.floor(Math.random() * pointsDelta);
  27. var path = createBlob(view.size * Point.random(), radius, points);
  28. var lightness = (Math.random() - 0.5) * 0.4 + 0.4;
  29. var hue = Math.random() * 360;
  30. path.fillColor = { hue: hue, saturation: 1, lightness: lightness };
  31. path.strokeColor = 'black';
  32. };
  33. function createBlob(center, maxRadius, points) {
  34. var path = new Path();
  35. path.closed = true;
  36. for (var i = 0; i < points; i++) {
  37. var delta = new Point({
  38. length: (maxRadius * 0.5) + (Math.random() * maxRadius * 0.5),
  39. angle: (360 / points) * i
  40. });
  41. path.add(center + delta);
  42. }
  43. path.smooth();
  44. return path;
  45. }
  46. var segment, path;
  47. function onMouseDown(event) {
  48. segment = path = null;
  49. var hitResult = project.hitTest(event.point, hitOptions);
  50. if (event.modifiers.shift) {
  51. if (hitResult.type == 'segment') {
  52. hitResult.segment.remove();
  53. };
  54. return;
  55. }
  56. if (hitResult) {
  57. path = hitResult.item;
  58. if (hitResult.type == 'segment') {
  59. segment = hitResult.segment;
  60. } else if (hitResult.type == 'stroke') {
  61. var location = hitResult.location;
  62. segment = path.insert(location.index + 1, event.point);
  63. path.smooth();
  64. }
  65. hitResult.item.bringToFront();
  66. }
  67. }
  68. function onMouseMove(event) {
  69. var hitResult = project.hitTest(event.point, hitOptions);
  70. project.activeLayer.selected = false;
  71. if (hitResult && hitResult.item)
  72. hitResult.item.selected = true;
  73. }
  74. function onMouseDrag(event) {
  75. if (segment) {
  76. segment.point += event.delta;
  77. path.smooth();
  78. } else if (path) {
  79. path.position += event.delta;
  80. }
  81. }
  82. </script>
  83. </head>
  84. <body style="background:black">
  85. <canvas id="canvas" resize></canvas>
  86. </body>
  87. </html>