@turbowarp/paper 0.12.202407161743

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/AUTHORS.md +18 -0
  2. package/CHANGELOG.md +701 -0
  3. package/LICENSE.txt +23 -0
  4. package/README.md +381 -0
  5. package/dist/node/canvas.js +66 -0
  6. package/dist/node/extend.js +156 -0
  7. package/dist/node/self.js +58 -0
  8. package/dist/node/xml.js +40 -0
  9. package/dist/paper-core.js +15805 -0
  10. package/dist/paper-full.js +17574 -0
  11. package/examples/Animated/AnimatedStar.html +53 -0
  12. package/examples/Animated/BooleanOperations.html +115 -0
  13. package/examples/Animated/CandyCrash.html +151 -0
  14. package/examples/Animated/Extruded.html +50 -0
  15. package/examples/Animated/Lines.html +53 -0
  16. package/examples/Animated/Smoothing.html +70 -0
  17. package/examples/Animated/Space.html +86 -0
  18. package/examples/Animated/SpaceUsingShapes.html +79 -0
  19. package/examples/Games/Paperoids.html +569 -0
  20. package/examples/JSON/Circle Testing.html +34 -0
  21. package/examples/JSON/Compound Path.html +25 -0
  22. package/examples/JSON/Empty Path Testing.html +31 -0
  23. package/examples/JSON/Gradients.html +34 -0
  24. package/examples/JSON/Group Transform.html +28 -0
  25. package/examples/JSON/Line Testing.html +44 -0
  26. package/examples/JSON/Random Path Testing.html +42 -0
  27. package/examples/JSON/Raster.html +29 -0
  28. package/examples/JSON/Rect and Attribute Testing.html +56 -0
  29. package/examples/JSON/Rotated Primitives.html +55 -0
  30. package/examples/JSON/Selection.html +43 -0
  31. package/examples/JSON/Shapes.html +54 -0
  32. package/examples/JSON/Symbols.html +30 -0
  33. package/examples/JSON/Text Testing.html +38 -0
  34. package/examples/JSON/Tiger.html +19 -0
  35. package/examples/JSON/Transform Test 1.html +32 -0
  36. package/examples/JSON/Transform Test 2.html +30 -0
  37. package/examples/Node.js/AnimatedStar.js +52 -0
  38. package/examples/Node.js/BooleanOperations.js +36 -0
  39. package/examples/Node.js/JSONtoPDF.js +20 -0
  40. package/examples/Node.js/Raster.js +32 -0
  41. package/examples/Node.js/RasterRemote.js +33 -0
  42. package/examples/Node.js/SvgExport.js +52 -0
  43. package/examples/Node.js/SvgImport.js +23 -0
  44. package/examples/Node.js/Tadpoles.js +16 -0
  45. package/examples/Node.js/Tadpoles.pjs +278 -0
  46. package/examples/Node.js/in.json +1 -0
  47. package/examples/Node.js/in.svg +16 -0
  48. package/examples/Paperjs.org/BooleanOperattions.html +115 -0
  49. package/examples/Paperjs.org/BouncingBalls.html +103 -0
  50. package/examples/Paperjs.org/Chain.html +54 -0
  51. package/examples/Paperjs.org/DivisionRaster.html +72 -0
  52. package/examples/Paperjs.org/FutureSplash.html +122 -0
  53. package/examples/Paperjs.org/HitTesting.html +103 -0
  54. package/examples/Paperjs.org/InteractiveTiger.html +777 -0
  55. package/examples/Paperjs.org/MetaBalls.html +132 -0
  56. package/examples/Paperjs.org/NyanRainbow.html +202 -0
  57. package/examples/Paperjs.org/PathIntersections.html +76 -0
  58. package/examples/Paperjs.org/Qbertify.html +146 -0
  59. package/examples/Paperjs.org/RadialRainbows.html +80 -0
  60. package/examples/Paperjs.org/RoundedRectangles.html +41 -0
  61. package/examples/Paperjs.org/SatieLikedToDraw.html +140 -0
  62. package/examples/Paperjs.org/Simplify.html +63 -0
  63. package/examples/Paperjs.org/SpiralRaster.html +120 -0
  64. package/examples/Paperjs.org/Tadpoles.html +283 -0
  65. package/examples/Paperjs.org/Voronoi.html +134 -0
  66. package/examples/Rasters/PhyllotaxisRaster.html +96 -0
  67. package/examples/Rasters/Raster.html +34 -0
  68. package/examples/Rasters/RotationRaster.html +44 -0
  69. package/examples/Rasters/Smoothing.html +48 -0
  70. package/examples/SVG Export/Circle Testing.html +32 -0
  71. package/examples/SVG Export/Clipping.html +17 -0
  72. package/examples/SVG Export/Compound Path.html +22 -0
  73. package/examples/SVG Export/Empty Path Testing.html +28 -0
  74. package/examples/SVG Export/Gradients.html +52 -0
  75. package/examples/SVG Export/Group Transform.html +25 -0
  76. package/examples/SVG Export/Line Testing.html +41 -0
  77. package/examples/SVG Export/Random Path Testing.html +39 -0
  78. package/examples/SVG Export/Raster.html +21 -0
  79. package/examples/SVG Export/Rect and Attribute Testing.html +53 -0
  80. package/examples/SVG Export/Rotated Primitives.html +80 -0
  81. package/examples/SVG Export/Shapes.html +58 -0
  82. package/examples/SVG Export/Symbols.html +27 -0
  83. package/examples/SVG Export/Text Testing.html +45 -0
  84. package/examples/SVG Export/Tiger.html +23 -0
  85. package/examples/SVG Export/Transform Test 1.html +29 -0
  86. package/examples/SVG Export/Transform Test 2.html +27 -0
  87. package/examples/SVG Import/Arcs.html +78 -0
  88. package/examples/SVG Import/Butterfly.html +223 -0
  89. package/examples/SVG Import/Circle and Ellipse Testing.html +26 -0
  90. package/examples/SVG Import/Clipping.html +100 -0
  91. package/examples/SVG Import/From File.html +30 -0
  92. package/examples/SVG Import/Gradient.html +138 -0
  93. package/examples/SVG Import/Gradients.html +30 -0
  94. package/examples/SVG Import/Inkscape Pivot.html +52 -0
  95. package/examples/SVG Import/Inkscape.html +88 -0
  96. package/examples/SVG Import/Line Testing.html +24 -0
  97. package/examples/SVG Import/MoreGradients.html +107 -0
  98. package/examples/SVG Import/Multiple Paths Test 1.html +42 -0
  99. package/examples/SVG Import/Multiple Paths Test 2.html +33 -0
  100. package/examples/SVG Import/Nested Groups Test.html +78 -0
  101. package/examples/SVG Import/Polybezier.html +43 -0
  102. package/examples/SVG Import/Rect Testing.html +25 -0
  103. package/examples/SVG Import/Symbols.html +24 -0
  104. package/examples/SVG Import/Testing.html +40 -0
  105. package/examples/SVG Import/Text Testing.html +19 -0
  106. package/examples/SVG Import/Tiger.html +742 -0
  107. package/examples/SVG Import/Transform Testing.html +22 -0
  108. package/examples/SVG Import/Viewbox.html +38 -0
  109. package/examples/Scripts/Arcs.html +39 -0
  110. package/examples/Scripts/BlendModes.html +77 -0
  111. package/examples/Scripts/BooleanOperations.html +937 -0
  112. package/examples/Scripts/CompoundPath.html +19 -0
  113. package/examples/Scripts/CurveTimeParameterization.html +61 -0
  114. package/examples/Scripts/HslColor.html +53 -0
  115. package/examples/Scripts/PathStructure.html +82 -0
  116. package/examples/Scripts/PathTangents.html +73 -0
  117. package/examples/Scripts/Resize.html +42 -0
  118. package/examples/Scripts/RoundRectangle.html +28 -0
  119. package/examples/Scripts/Shapes.html +54 -0
  120. package/examples/Scripts/StrokeBounds.html +101 -0
  121. package/examples/Scripts/StrokeScaling.html +65 -0
  122. package/examples/Tools/BezierTool.html +90 -0
  123. package/examples/Tools/Circles.html +28 -0
  124. package/examples/Tools/Clouds.html +35 -0
  125. package/examples/Tools/DrippingBrush.html +73 -0
  126. package/examples/Tools/FancyBrush.html +82 -0
  127. package/examples/Tools/Grid.html +44 -0
  128. package/examples/Tools/MultiLines.html +44 -0
  129. package/examples/Tools/MultipleTools.html +44 -0
  130. package/examples/Tools/PathEditing.html +95 -0
  131. package/examples/Tools/SquareRounded.html +76 -0
  132. package/examples/Tools/Stars.html +38 -0
  133. package/examples/Tools/Vektor.html +200 -0
  134. package/examples/Tools/Wave.html +50 -0
  135. package/examples/Tools/WormFarm.html +88 -0
  136. package/examples/Worker/Main.html +53 -0
  137. package/examples/Worker/Worker.js +14 -0
  138. package/examples/css/style.css +12 -0
  139. package/package.json +109 -0
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Circles</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
+ function onMouseDrag(event) {
10
+ // The radius is the distance between the position
11
+ // where the user clicked and the current position
12
+ // of the mouse.
13
+ var path = new Path.Circle({
14
+ center: event.downPoint,
15
+ radius: (event.downPoint - event.point).length,
16
+ fillColor: 'white',
17
+ strokeColor: 'black'
18
+ });
19
+
20
+ // Remove this path on the next drag event:
21
+ path.removeOnDrag();
22
+ };
23
+ </script>
24
+ </head>
25
+ <body>
26
+ <canvas id="canvas" resize></canvas>
27
+ </body>
28
+ </html>
@@ -0,0 +1,35 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Clouds</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
+ // Any newly created item will inherit the following styles:
10
+ project.currentStyle = {
11
+ strokeColor: 'black',
12
+ strokeWidth: 5,
13
+ strokeJoin: 'round',
14
+ strokeCap: 'round'
15
+ };
16
+
17
+ // The user has to drag the mouse at least 30pt before the mouse drag
18
+ // event is fired:
19
+ tool.minDistance = 30;
20
+
21
+ var path;
22
+ function onMouseDown(event) {
23
+ path = new Path();
24
+ path.add(event.point);
25
+ }
26
+
27
+ function onMouseDrag(event) {
28
+ path.arcTo(event.point, true);
29
+ }
30
+ </script>
31
+ </head>
32
+ <body>
33
+ <canvas id="canvas" resize></canvas>
34
+ </body>
35
+ </html>
@@ -0,0 +1,73 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Dripping 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
+ var path;
10
+ var minSize = 5;
11
+ tool.maxDistance = 20;
12
+ function onMouseDrag(event) {
13
+ // If the user dragged more then minSize:
14
+ if (event.delta.length > minSize) {
15
+ // If there is no path, make one:
16
+ if (!path) {
17
+ path = new Path({
18
+ fillColor: 'black'
19
+ });
20
+ path.add(event.lastPoint);
21
+ }
22
+
23
+ var step = event.delta / 2;
24
+ step.angle = step.angle + 90;
25
+
26
+ // The top point: the middle point + the step rotated by 90 degrees:
27
+ // -----*
28
+ // |
29
+ // ------
30
+ var top = event.middlePoint + step;
31
+
32
+ // The bottom point: the middle point - the step rotated by 90 degrees:
33
+ // ------
34
+ // |
35
+ // -----*
36
+ var bottom = event.middlePoint - step;
37
+
38
+ path.add(top);
39
+ path.insert(0, bottom);
40
+ path.smooth();
41
+ } else {
42
+ // If the user dragged too slowly:
43
+
44
+ // If there is currently a path, close it
45
+ if (path) {
46
+ path.add(event.point);
47
+ path.closed = true;
48
+ path.smooth();
49
+
50
+ // Set path to null (nothing) so the path check above
51
+ // will force a new path next time the user drags fast enough:
52
+ path = null;
53
+ }
54
+ }
55
+ }
56
+
57
+ function onMouseUp(event) {
58
+ if (path) {
59
+ path.add(event.point);
60
+ path.closed = true;
61
+ path.smooth();
62
+
63
+ // Set path to null (nothing) so the path check above
64
+ // will force a new path next time the user drags fast enough:
65
+ path = null;
66
+ }
67
+ }
68
+ </script>
69
+ </head>
70
+ <body>
71
+ <canvas id="canvas" resize></canvas>
72
+ </body>
73
+ </html>
@@ -0,0 +1,82 @@
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
+
14
+ tool.fixedDistance = 80;
15
+
16
+ var path;
17
+ var strokeEnds = 6;
18
+
19
+ function onMouseDown(event) {
20
+ path = new Path();
21
+ path.fillColor = event.count % 2 ? 'red' : 'black';
22
+ }
23
+
24
+ var lastPoint;
25
+ function onMouseDrag(event) {
26
+ // If this is the first drag event,
27
+ // add the strokes at the start:
28
+ if (event.count == 0) {
29
+ addStrokes(event.middlePoint, event.delta * -1);
30
+ } else {
31
+ var step = event.delta / 2;
32
+ step.angle += 90;
33
+
34
+ // The top point: the middle point + the step rotated by 90 degrees:
35
+ // -----*
36
+ // |
37
+ // ------
38
+ var top = event.middlePoint + step;
39
+
40
+ // The bottom point: the middle point - the step rotated by 90 degrees:
41
+ // ------
42
+ // |
43
+ // -----*
44
+ var bottom = event.middlePoint - step;
45
+
46
+ path.add(top);
47
+ path.insert(0, bottom);
48
+ }
49
+ path.smooth();
50
+
51
+ lastPoint = event.middlePoint;
52
+ }
53
+
54
+ function onMouseUp(event) {
55
+ var delta = event.point - lastPoint;
56
+ delta.length = tool.maxDistance;
57
+ addStrokes(event.point, delta);
58
+ path.closed = true;
59
+ path.smooth();
60
+ }
61
+
62
+ function addStrokes(point, delta) {
63
+ var step = delta.rotate(90);
64
+ var strokePoints = strokeEnds * 2 + 1;
65
+ point -= step / 2;
66
+ step /= strokePoints - 1;
67
+ for (var i = 0; i < strokePoints; i++) {
68
+ var strokePoint = point + step * i;
69
+ var offset = delta * (Math.random() * 0.3 + 0.1);
70
+ if (i % 2) {
71
+ offset *= -1;
72
+ }
73
+ strokePoint += offset;
74
+ path.insert(0, strokePoint);
75
+ }
76
+ }
77
+ </script>
78
+ </head>
79
+ <body>
80
+ <canvas id="canvas" resize></canvas>
81
+ </body>
82
+ </html>
@@ -0,0 +1,44 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Grid</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
+
12
+ tool.fixedDistance = 10;
13
+
14
+ var values = { size: tool.fixedDistance };
15
+
16
+ /////////////////////////////////////////////////////////////////////
17
+ // Mouse handling
18
+
19
+ var point, path;
20
+
21
+ function getPos(pt) {
22
+ return (pt / values.size).round() * values.size;
23
+ }
24
+
25
+ function onMouseDown(event) {
26
+ point = getPos(event.point);
27
+ path = new Path();
28
+ path.strokeColor = 'black';
29
+ path.add(point);
30
+ }
31
+
32
+ function onMouseDrag(event) {
33
+ var p = getPos(event.point);
34
+ if (point != p) {
35
+ path.add(p);
36
+ point = p;
37
+ }
38
+ }
39
+ </script>
40
+ </head>
41
+ <body>
42
+ <canvas id="canvas" resize></canvas>
43
+ </body>
44
+ </html>
@@ -0,0 +1,44 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Multi Lines</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
+ tool.fixedDistance = 30;
10
+
11
+ var values = {
12
+ lines: 5,
13
+ size: 40,
14
+ smooth: true
15
+ };
16
+
17
+ var paths;
18
+
19
+ function onMouseDown(event) {
20
+ paths = [];
21
+ for (var i = 0; i < values.lines; i++) {
22
+ var path = new Path();
23
+ path.strokeColor = '#000000';
24
+ paths.push(path);
25
+ }
26
+ }
27
+
28
+ function onMouseDrag(event) {
29
+ var offset = event.delta;
30
+ offset.angle = offset.angle + 90;
31
+ var lineSize = values.size / values.lines;
32
+ for (var i = 0; i < values.lines; i++) {
33
+ var path = paths[values.lines - 1 - i];
34
+ offset.length = lineSize * i + lineSize / 2;
35
+ path.add(event.middlePoint + offset);
36
+ path.smooth();
37
+ }
38
+ }
39
+ </script>
40
+ </head>
41
+ <body>
42
+ <canvas id="canvas" resize></canvas>
43
+ </body>
44
+ </html>
@@ -0,0 +1,44 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Mulitple Tools</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
+ // Create two drawing tools.
10
+ // tool1 will draw straight lines, tool2 will draw clouds.
11
+
12
+ // Both share the mouseDown event:
13
+ var path;
14
+ function onMouseDown(event) {
15
+ path = new Path();
16
+ path.strokeColor = 'black';
17
+ path.add(event.point);
18
+ }
19
+
20
+ window.app = {
21
+ tool1: new Tool({
22
+ onMouseDown: onMouseDown,
23
+ onMouseDrag: function(event) {
24
+ path.add(event.point);
25
+ }
26
+ }),
27
+
28
+ tool2: new Tool({
29
+ minDistance: 20,
30
+ onMouseDown: onMouseDown,
31
+ onMouseDrag: function(event) {
32
+ // Use the arcTo command to draw cloudy lines
33
+ path.arcTo(event.point);
34
+ }
35
+ })
36
+ };
37
+ </script>
38
+ </head>
39
+ <body>
40
+ <a href="#" onclick="app.tool1.activate(); return false;">Lines</a>
41
+ <a href="#" onclick="app.tool2.activate(); return false;">Clouds</a>
42
+ <canvas id="canvas" resize></canvas>
43
+ </body>
44
+ </html>
@@ -0,0 +1,95 @@
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
+
17
+ var hitOptions = {
18
+ segments: true,
19
+ stroke: true,
20
+ fill: true,
21
+ tolerance: 5
22
+ };
23
+
24
+ var radiusDelta = values.maxRadius - values.minRadius;
25
+ var pointsDelta = values.maxPoints - values.minPoints;
26
+ for (var i = 0; i < values.paths; i++) {
27
+ var radius = values.minRadius + Math.random() * radiusDelta;
28
+ var points = values.minPoints + Math.floor(Math.random() * pointsDelta);
29
+ var path = createBlob(view.size * Point.random(), radius, points);
30
+ var lightness = (Math.random() - 0.5) * 0.4 + 0.4;
31
+ var hue = Math.random() * 360;
32
+ path.fillColor = { hue: hue, saturation: 1, lightness: lightness };
33
+ path.strokeColor = 'black';
34
+ };
35
+
36
+ function createBlob(center, maxRadius, points) {
37
+ var path = new Path();
38
+ path.closed = true;
39
+ for (var i = 0; i < points; i++) {
40
+ var delta = new Point({
41
+ length: (maxRadius * 0.5) + (Math.random() * maxRadius * 0.5),
42
+ angle: (360 / points) * i
43
+ });
44
+ path.add(center + delta);
45
+ }
46
+ path.smooth();
47
+ return path;
48
+ }
49
+
50
+ var segment, path;
51
+ function onMouseDown(event) {
52
+ segment = path = null;
53
+ var hitResult = project.hitTest(event.point, hitOptions);
54
+
55
+ if (event.modifiers.shift) {
56
+ if (hitResult.type == 'segment') {
57
+ hitResult.segment.remove();
58
+ };
59
+ return;
60
+ }
61
+
62
+ if (hitResult) {
63
+ path = hitResult.item;
64
+ if (hitResult.type == 'segment') {
65
+ segment = hitResult.segment;
66
+ } else if (hitResult.type == 'stroke') {
67
+ var location = hitResult.location;
68
+ segment = path.insert(location.index + 1, event.point);
69
+ path.smooth();
70
+ }
71
+ hitResult.item.bringToFront();
72
+ }
73
+ }
74
+
75
+ function onMouseMove(event) {
76
+ var hitResult = project.hitTest(event.point, hitOptions);
77
+ project.activeLayer.selected = false;
78
+ if (hitResult && hitResult.item)
79
+ hitResult.item.selected = true;
80
+ }
81
+
82
+ function onMouseDrag(event) {
83
+ if (segment) {
84
+ segment.point += event.delta;
85
+ path.smooth();
86
+ } else if (path) {
87
+ path.position += event.delta;
88
+ }
89
+ }
90
+ </script>
91
+ </head>
92
+ <body style="background:black">
93
+ <canvas id="canvas" resize></canvas>
94
+ </body>
95
+ </html>
@@ -0,0 +1,76 @@
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
+
12
+ var values = {
13
+ radius: 10,
14
+ tolerance: 5
15
+ };
16
+
17
+ checkValues();
18
+
19
+ /////////////////////////////////////////////////////////////////////
20
+ // Mouse handling
21
+
22
+ var handle;
23
+ function checkValues() {
24
+ var min = values.radius * 2;
25
+ if (values.tolerance < min) values.tolerance = min;
26
+ handle = values.radius * Numerical.KAPPA;
27
+ }
28
+
29
+ var path;
30
+ function onMouseDown(event) {
31
+ path = new Path({
32
+ segments: [event.point, event.point],
33
+ strokeColor: 'black',
34
+ strokeWidth: 5,
35
+ strokeCap: 'round'
36
+ });
37
+ prevPoint = path.firstSegment.point;
38
+ curPoint = path.lastSegment.point;
39
+ curHandleSeg = null;
40
+ }
41
+
42
+ var curPoint, prevPoint, curHandleSeg;
43
+ function onMouseDrag(event) {
44
+ var point = event.point;
45
+ var diff = (point - prevPoint).abs();
46
+ if (diff.x < diff.y) {
47
+ curPoint.x = prevPoint.x;
48
+ curPoint.y = point.y;
49
+ } else {
50
+ curPoint.x = point.x;
51
+ curPoint.y = prevPoint.y;
52
+ }
53
+ var normal = curPoint - prevPoint;
54
+ normal.length = 1;
55
+ if (curHandleSeg) {
56
+ curHandleSeg.point = prevPoint + (normal * values.radius);
57
+ curHandleSeg.handleIn = normal * -handle;
58
+ }
59
+ var minDiff = Math.min(diff.x, diff.y);
60
+ if (minDiff > values.tolerance) {
61
+ var point = curPoint - (normal * values.radius);
62
+ var segment = new Segment(point, null, normal * handle);
63
+ path.insert(path.segments.length - 1, segment);
64
+ curHandleSeg = path.lastSegment;
65
+ // clone as we want the unmodified one:
66
+ prevPoint = curHandleSeg.point.clone();
67
+ path.add(curHandleSeg);
68
+ curPoint = path.lastSegment.point;
69
+ }
70
+ }
71
+ </script>
72
+ </head>
73
+ <body>
74
+ <canvas id="canvas" resize></canvas>
75
+ </body>
76
+ </html>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Stars</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
+ function onMouseDown(event) {
10
+ var hue = Math.random() * 360;
11
+ project.currentStyle.fillColor = {
12
+ hue: hue,
13
+ saturation: 1,
14
+ brightness: 1
15
+ };
16
+ }
17
+
18
+ function onMouseDrag(event) {
19
+ var delta = event.point - event.downPoint;
20
+ var radius = delta.length;
21
+ var points = 5 + Math.round(radius / 50);
22
+ var path = new Path.Star({
23
+ center: event.downPoint,
24
+ points: points,
25
+ radius1: radius / 2,
26
+ radius2: radius
27
+ });
28
+ path.rotate(delta.angle);
29
+ // Remove the path automatically before the next mouse drag
30
+ // event:
31
+ path.removeOnDrag();
32
+ }
33
+ </script>
34
+ </head>
35
+ <body>
36
+ <canvas id="canvas" resize></canvas>
37
+ </body>
38
+ </html>