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.

82 lines
2.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Fancy Brush</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. // This script belongs to the following tutorial:
  11. //
  12. // http://scriptographer.org/tutorials/geometry/working-with-mouse-vectors/#adding-brush-stroke-ends
  13. tool.fixedDistance = 80;
  14. var path;
  15. var strokeEnds = 6;
  16. function onMouseDown(event) {
  17. path = new Path();
  18. path.fillColor = event.count % 2 ? 'red' : 'black';
  19. }
  20. var lastPoint;
  21. function onMouseDrag(event) {
  22. // If this is the first drag event,
  23. // add the strokes at the start:
  24. if (event.count == 0) {
  25. addStrokes(event.middlePoint, event.delta * -1);
  26. } else {
  27. var step = event.delta / 2;
  28. step.angle += 90;
  29. // The top point: the middle point + the step rotated by 90 degrees:
  30. // -----*
  31. // |
  32. // ------
  33. var top = event.middlePoint + step;
  34. // The bottom point: the middle point - the step rotated by 90 degrees:
  35. // ------
  36. // |
  37. // -----*
  38. var bottom = event.middlePoint - step;
  39. path.add(top);
  40. path.insert(0, bottom);
  41. }
  42. path.smooth();
  43. lastPoint = event.middlePoint;
  44. }
  45. function onMouseUp(event) {
  46. var delta = event.point - lastPoint;
  47. delta.length = tool.maxDistance;
  48. addStrokes(event.point, delta);
  49. path.closed = true;
  50. path.smooth();
  51. }
  52. function addStrokes(point, delta) {
  53. var step = delta.rotate(90);
  54. var strokePoints = strokeEnds * 2 + 1;
  55. point -= step / 2;
  56. step /= strokePoints - 1;
  57. for (var i = 0; i < strokePoints; i++) {
  58. var strokePoint = point + step * i;
  59. var offset = delta * (Math.random() * 0.3 + 0.1);
  60. if (i % 2) {
  61. offset *= -1;
  62. }
  63. strokePoint += offset;
  64. path.insert(0, strokePoint);
  65. }
  66. }
  67. </script>
  68. </head>
  69. <body>
  70. <canvas id="canvas" resize></canvas>
  71. </body>
  72. </html>