p5bezier 0.3.0 → 0.3.2

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.
package/README.md CHANGED
@@ -2,9 +2,14 @@
2
2
 
3
3
  ![cover](img/cover.jpg)
4
4
 
5
- Hi! Don't wait and let **p5.bezier**, a [p5.js](https://p5js.org) library, help you draw the smoothest curves like never before. You can regard the library as an advanced version of the original p5.js `bezier()` function which takes no less or more than 4 points while cannot draw higher level curves. The p5.bezier library allows you to draw continuous and closed Bézier curves easily.
5
+ [![npm version](https://img.shields.io/npm/v/p5bezier.svg?style=flat-square)](https://npmjs.org/package/p5bezier)
6
+ [![GitHub license](https://img.shields.io/github/license/peilingjiang/p5.bezier?style=flat-square)](https://github.com/peilingjiang/p5.bezier/blob/main/LICENSE)
7
+ [![](https://data.jsdelivr.com/v1/package/npm/p5bezier/badge)](https://www.jsdelivr.com/package/npm/p5bezier)
6
8
 
7
- [**Try it now on p5.js Web Editor!**](https://editor.p5js.org/peilingjiang/sketches/7Z2pRG-TB)
9
+ Let **p5.bezier**, a [p5.js](https://p5js.org) library, help you draw the smoothest curves like never before. You can regard the library as an advanced version of the original p5.js `bezier()` function which takes no less or more than 4 points while cannot draw higher level curves. The p5.bezier library allows you to draw continuous and closed Bézier curves easily.
10
+
11
+ <!-- [**Try it now on p5.js Web Editor!**](https://editor.p5js.org/peilingjiang/sketches/7Z2pRG-TB) -->
12
+ [**Try it now on p5.js Web Editor!**](https://editor.p5js.org/peilingjiang/sketches/mVXzWEJbT)
8
13
 
9
14
  **0.2.0 NEW** The library is now independent of p5.js so that you can use it for a wider range of projects (untested). However, an extra `initBezier(canvas)` line is needed before the drawings.
10
15
 
@@ -26,7 +31,7 @@ A Bézier curve is a parametric curve used in computer graphics and related fiel
26
31
 
27
32
  ## Getting Started
28
33
 
29
- To use p5.bezier library, download [p5.bezier.min.js](https://raw.githubusercontent.com/peilingjiang/p5.bezier/master/lib/p5.bezier.min.js) file into your project directory and add the following line into the your HTML file:
34
+ To use p5.bezier library, download [p5.bezier.min.js](https://raw.githubusercontent.com/peilingjiang/p5.bezier/main/lib/p5.bezier.min.js) file into your project directory and add the following line into the your HTML file:
30
35
 
31
36
  ```HTML
32
37
  <script src="p5.bezier.min.js"></script>
@@ -51,7 +56,7 @@ The library is still a work-in-progress project. Therefore, code tends to change
51
56
  You can also install using the package manager NPM (recommended):
52
57
 
53
58
  ```
54
- npm install --save p5bezier
59
+ npm install p5bezier
55
60
  ```
56
61
 
57
62
  And then import the modules into your project:
@@ -89,7 +94,7 @@ Takes a string, either `"OPEN"` or `"CLOSE"`. If you want the curve to close its
89
94
 
90
95
  **fidelity** (Optional)
91
96
 
92
- Takes an integer from `0` to `10`, as default is `7`. How accurate you want the Bézier curve to be. The more inner vertices used to draw the curve, the more accurate it would be, however, the more computation would also be cost.
97
+ Takes an integer from `0` to `10`, as default is `6`. How accurate you want the Bézier curve to be. The more inner vertices used to draw the curve, the more accurate it would be, however, the more computation would also be cost.
93
98
 
94
99
  ## Create a Bézier Object
95
100
 
@@ -148,17 +153,21 @@ For instance, if you want to run the example _basic_, simply type `node server.j
148
153
  Currently available examples:
149
154
 
150
155
  - **basic** draws a simple Bézier curve with 5 control points across the canvas.
156
+ - **basic_object** create a simple Bézier object with 5 control points across the canvas.
151
157
  - **control_points** draws a curve and it's control points, which can be dragged around.
152
158
  - **fidelity** draws curves with different fidelities.
153
159
  - **basic_object** is similar to basic, while drew with Bézier object.
154
160
  - **shortest_point** draws the shortest line from mouse to curve.
155
161
 
162
+ - **perlin** Use Perlin Noise (from p5.js) to control moving Bézier curves.
163
+
156
164
  More complex examples to be updated.
157
165
 
158
166
  ### Projects and Live Demo
159
167
 
160
168
  - [**Hair**](https://no-loss.netlify.app/), a visualization. See the source code here: https://github.com/peilingjiang/hair.
161
169
  - *p5.bezier Example - Basic* on [CodePen](https://codepen.io/peilingjiang/pen/ZEOLVPx).
170
+ - *p5.bezier Example - Perlin* on [CodePen](https://codepen.io/peilingjiang/pen/eYMRJax).
162
171
 
163
172
  Share your ideas and projects using the library!
164
173
 
@@ -1,3 +1,3 @@
1
1
  /*! For license information please see p5.bezier.min.js.LICENSE.txt */
2
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.p5bezier=t():e.p5bezier=t()}(self,(function(){return(()=>{"use strict";var e={d:(t,r)=>{for(var i in r)e.o(r,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:r[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{initBezier:()=>f,newBezier:()=>d,newBezierObj:()=>u});const r=[.2,.1,.05,.04,.02,.01,.008,.002,.001,5e-4,1e-4];let i,n,o,s,h,l,a,p,c;function f(e,t=!1){if(i=e,n=i.drawingContext,p5&&e instanceof p5.Graphics)h=!0,o="WebGLRenderingContext"===n.constructor.name?3:2,l=i.beginShape,a=i.vertex,p=i.vertex,c=i.endShape;else{if(!(p5&&e instanceof p5.Renderer||e.drawingContext))throw new Error("[p5.bezier] Canvas is not supported.");p5&&(!p5||e instanceof p5.Renderer)?o="WebGLRenderingContext"===n.constructor.name?3:2:(window.console.warn("[p5.bezier] Support for non-p5 canvas is not tested."),o=e.isP3D?3:2),h=!1,o="WebGLRenderingContext"===n.constructor.name?3:2,l=n.beginPath.bind(n),a=n.moveTo.bind(n),p=n.lineTo.bind(n),c=n.closePath.bind(n)}s=t}function d(e,t="OPEN",i=7){if(s&&!Array.isArray(e))throw new Error(`[p5.bezier] newBezier() function expects an array, got ${typeof e}.`);const n=r[i];if(0===o);else{if(s)for(let t of e)if(!Array.isArray(e)||t.length!==o)throw new Error("[p5.bezier] One or more points in the array are not input correctly.");"CLOSE"===t&&e.push(e[0]);let r=e.length-1;if(l(),a(...e[0]),2===o){let t,i,o,s;for(o=0;o<=1;o+=n){for(t=0,i=0,s=0;s<=r;s++)t+=w(r)/(w(s)*w(r-s))*Math.pow(1-o,r-s)*Math.pow(o,s)*e[s][0],i+=w(r)/(w(s)*w(r-s))*Math.pow(1-o,r-s)*Math.pow(o,s)*e[s][1];p(t,i)}p(...e.slice(-1)[0])}else if(3===o){let t,i,o,s=[0,0,0];for(t=0;t<=1;t+=n){for(s=[0,0,0],i=0;i<=r;i++)for(o=0;o<3;o++)s[o]+=w(r)/(w(i)*w(r-i))*Math.pow(1-t,r-i)*Math.pow(t,i)*e[i][o];p(...s)}p(...e.slice(-1)[0])}if(h)c(t);else if("CLOSE"===t)c();else if(s&&"OPEN"!==t)throw new Error("[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.");x()}}function u(e,t="OPEN",i=7){const n=r[i];if(s&&!Array.isArray(e))throw new Error(`[p5.bezier] newBezierObj() function expects an array, got ${typeof e}.`);if(s)for(let t of e)if(!Array.isArray(e)||t.length!==o)throw new Error("[p5.bezier] One or more points in the array are not input correctly.");return new b(e,t,n,o)}function w(e){return e>1?e*w(e-1):1}function y(){return 4===arguments.length?Math.hypot(arguments[0]-arguments[2],arguments[1]-arguments[3]):6===arguments.length?Math.hypot(arguments[0]-arguments[3],arguments[1]-arguments[4],arguments[2]-arguments[5]):0}function x(){i._doFill&&n.fill(),i._doStroke&&n.stroke()}class b{constructor(e,t,r,i,n=null){if(s&&2!==i&&3!==i)throw new Error(`Dimension error. The bezier curve is ${i}-dimensional and doesn't belong to our world.`);if(this.controlPoints=e,"CLOSE"===t)this.controlPoints.push(e[0]),this.closeType="CLOSE";else{if("OPEN"!==t)throw new Error("[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.");this.closeType="OPEN"}this.dimension=i,this.increment=r,this.vertexList=[],this.vertexListLen=0,this.p=this.controlPoints.length,this.n=this.p-1,null===n?this._buildVertexList():(this.vertexList=n,this.vertexListLen=this.vertexList.length)}_buildVertexList(){if(this.vertexList=[],2===this.dimension){let e,t,r,i;for(r=0;r<=1;r+=this.increment){for(e=0,t=0,i=0;i<=this.n;i++)e+=w(this.n)/(w(i)*w(this.n-i))*Math.pow(1-r,this.n-i)*Math.pow(r,i)*this.controlPoints[i][0],t+=w(this.n)/(w(i)*w(this.n-i))*Math.pow(1-r,this.n-i)*Math.pow(r,i)*this.controlPoints[i][1];this.vertexList.push([e,t])}}else if(3===this.dimension){let e,t,r,i=[0,0,0];for(e=0;e<=1;e+=this.increment){for(i[0]=0,i[1]=0,i[2]=0,t=0;t<=this.n;t++)for(r=0;r<3;r++)i[r]+=w(this.n)/(w(t)*w(this.n-t))*Math.pow(1-e,this.n-t)*Math.pow(e,t)*this.controlPoints[t][r];this.vertexList.push(i)}}return this._addVertex(this.controlPoints.slice(-1)[0]),this.dimension=this.vertexList[0].length,this.vertexListLen=this.vertexList.length,this.vertexList}_addVertex(e){if(2!==this.dimension&&3!==this.dimension)throw new Error("Vertices can only be in 2D or 3D space.");p(...e)}_distVertex(e,t){return 2===this.dimension?y(e[0],e[1],t[0],t[1]):3===this.dimension?y(e[0],e[1],e[2],t[0],t[1],t[2]):void 0}draw(e){if(e){if(!(Array.isArray(e)&&2===e.length&&this.increment<=.008))throw this.increment>.008?new Error("Fidelity is too low for a dash line. It should be at least 6."):new Error("Your dash array input is not valid. Make sure it's an array of two numbers.");{let t=Math.abs(e[0]),r=t+Math.abs(e[1]),i=0,o=0,s=this.vertexList[0],h=!0;n.save(),n.fillStyle="rgba(0, 0, 0, 0)",l(),a(...this.vertexList[0]);for(let e=1;e<this.vertexListLen;e++)i+=this._distVertex(s,this.vertexList[e]),o=i%r,o<=t&&h?this._addVertex(this.vertexList[e]):o>t&&o<=r&&h?h=!1:o<=t&&!h&&(a(...this.vertexList[e]),h=!0),s=this.vertexList[e];x(),n.restore()}}else{l();for(let e of this.vertexList)this._addVertex(e);"CLOSE"===this.closeType&&n.closePath(),h?c(this.closeType):"CLOSE"===this.closeType&&c(),x()}}update(e){if(e.length!==this.controlPoints.length)throw new Error("The number of points changed. (Keep the length of the point array the same.)");L(this.controlPoints,e)||(this.controlPoints=e,this._buildVertexList())}move(e,t,r=null,i=!0,n=0){if(null===r&&3===this.dimension)throw new Error("To move a 3D curve, please specify (x, y, z).");{let o=[e,t];null!==r&&o.push(r);let s=[];for(let e=0;e<this.vertexListLen;e++)s.push(this.vertexList[e].slice());let h=new b(this.controlPoints,this.closeType,this.increment,this.dimension,s);for(let e=0;e<h.vertexListLen;e++)for(let t=0;t<h.dimension;t++)h.vertexList[e][t]+=o[t];return i&&h.draw(n),h}}shortest(e,t,r=0){let i,n=-1,o=0;for(let s of this.vertexList)-1===n?(n=this._distVertex(s,[e,t,r]),i=s):(o=this._distVertex(s,[e,t,r]),n>o&&(n=o,i=s));return i}}const L=(e,t)=>e.length===t.length&&e.every(((e,r)=>e===t[r]));return t})()}));
2
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.p5bezier=t():e.p5bezier=t()}(self,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var i in r)e.o(r,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:r[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{initBezier:()=>f,newBezier:()=>d,newBezierObj:()=>u});const r=[.2,.1,.05,.04,.02,.01,.008,.002,.001,5e-4,1e-4];let i,o,n,s,h,l,a,p,c;function f(e,t=!1){if(i=e,o=i.drawingContext,p5&&e instanceof p5.Graphics)h=!0,n="WebGLRenderingContext"===o.constructor.name?3:2,l=i.beginShape,a=i.vertex,p=i.vertex,c=i.endShape;else{if(!(p5&&e instanceof p5.Renderer||e.drawingContext))throw new Error("[p5.bezier] Canvas is not supported.");p5&&(!p5||e instanceof p5.Renderer)?n="WebGLRenderingContext"===o.constructor.name?3:2:(window.console.warn("[p5.bezier] Support for non-p5 canvas is not tested."),n=e.isP3D?3:2),h=!1,n="WebGLRenderingContext"===o.constructor.name?3:2,l=o.beginPath.bind(o),a=o.moveTo.bind(o),p=o.lineTo.bind(o),c=o.closePath.bind(o)}s=t}function d(e,t="OPEN",i=6){if(s&&!Array.isArray(e))throw new Error(`[p5.bezier] newBezier() function expects an array, got ${typeof e}.`);const o=r[i];if(0===n);else{if(s)for(let t of e)if(!Array.isArray(e)||t.length!==n)throw new Error("[p5.bezier] One or more points in the array are not input correctly.");"CLOSE"===t&&e.push(e[0]);let r=e.length-1;if(l(),a(...e[0]),2===n){let t,i,n,s;for(n=0;n<=1;n+=o){for(t=0,i=0,s=0;s<=r;s++)t+=w(r)/(w(s)*w(r-s))*Math.pow(1-n,r-s)*Math.pow(n,s)*e[s][0],i+=w(r)/(w(s)*w(r-s))*Math.pow(1-n,r-s)*Math.pow(n,s)*e[s][1];p(t,i)}p(...e.slice(-1)[0])}else if(3===n){let t,i,n,s=[0,0,0];for(t=0;t<=1;t+=o){for(s=[0,0,0],i=0;i<=r;i++)for(n=0;n<3;n++)s[n]+=w(r)/(w(i)*w(r-i))*Math.pow(1-t,r-i)*Math.pow(t,i)*e[i][n];p(...s)}p(...e.slice(-1)[0])}if(h)c(t);else if("CLOSE"===t)c();else if(s&&"OPEN"!==t)throw new Error("[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.");x()}}function u(e,t="OPEN",i=6){const o=r[i];if(s&&!Array.isArray(e))throw new Error(`[p5.bezier] newBezierObj() function expects an array, got ${typeof e}.`);if(s)for(let t of e)if(!Array.isArray(e)||t.length!==n)throw new Error("[p5.bezier] One or more points in the array are not input correctly.");return new b(e,t,o,n)}function w(e){return e>1?e*w(e-1):1}function y(){return 4===arguments.length?Math.hypot(arguments[0]-arguments[2],arguments[1]-arguments[3]):6===arguments.length?Math.hypot(arguments[0]-arguments[3],arguments[1]-arguments[4],arguments[2]-arguments[5]):0}function x(){i._doFill&&o.fill(),i._doStroke&&o.stroke()}class b{constructor(e,t,r,i,o=null){if(s&&2!==i&&3!==i)throw new Error(`Dimension error. The bezier curve is ${i}-dimensional and doesn't belong to our world.`);if(this.controlPoints=e,"CLOSE"===t)this.controlPoints.push(e[0]),this.closeType="CLOSE";else{if("OPEN"!==t)throw new Error("[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.");this.closeType="OPEN"}this.dimension=i,this.increment=r,this.vertexList=[],this.vertexListLen=0,this.p=this.controlPoints.length,this.n=this.p-1,null===o?this._buildVertexList():(this.vertexList=o,this.vertexListLen=this.vertexList.length)}_buildVertexList(){if(this.vertexList=[],2===this.dimension){let e,t,r,i;for(r=0;r<=1;r+=this.increment){for(e=0,t=0,i=0;i<=this.n;i++)e+=w(this.n)/(w(i)*w(this.n-i))*Math.pow(1-r,this.n-i)*Math.pow(r,i)*this.controlPoints[i][0],t+=w(this.n)/(w(i)*w(this.n-i))*Math.pow(1-r,this.n-i)*Math.pow(r,i)*this.controlPoints[i][1];this.vertexList.push([e,t])}}else if(3===this.dimension){let e,t,r,i=[0,0,0];for(e=0;e<=1;e+=this.increment){for(i[0]=0,i[1]=0,i[2]=0,t=0;t<=this.n;t++)for(r=0;r<3;r++)i[r]+=w(this.n)/(w(t)*w(this.n-t))*Math.pow(1-e,this.n-t)*Math.pow(e,t)*this.controlPoints[t][r];this.vertexList.push(i)}}return this._addVertex(this.controlPoints.slice(-1)[0]),this.dimension=this.vertexList[0].length,this.vertexListLen=this.vertexList.length,this.vertexList}_addVertex(e){if(2!==this.dimension&&3!==this.dimension)throw new Error("Vertices can only be in 2D or 3D space.");p(...e)}_distVertex(e,t){return 2===this.dimension?y(e[0],e[1],t[0],t[1]):3===this.dimension?y(e[0],e[1],e[2],t[0],t[1],t[2]):void 0}draw(e){if(e){if(!(Array.isArray(e)&&2===e.length&&this.increment<=.008))throw this.increment>.008?new Error("Fidelity is too low for a dash line. It should be at least 6."):new Error("Your dash array input is not valid. Make sure it's an array of two numbers.");{let t=Math.abs(e[0]),r=t+Math.abs(e[1]),i=0,n=0,s=this.vertexList[0],h=!0;o.save(),o.fillStyle="rgba(0, 0, 0, 0)",l(),a(...this.vertexList[0]);for(let e=1;e<this.vertexListLen;e++)i+=this._distVertex(s,this.vertexList[e]),n=i%r,n<=t&&h?this._addVertex(this.vertexList[e]):n>t&&n<=r&&h?h=!1:n<=t&&!h&&(a(...this.vertexList[e]),h=!0),s=this.vertexList[e];x(),o.restore()}}else{l();for(let e of this.vertexList)this._addVertex(e);"CLOSE"===this.closeType&&o.closePath(),h?c(this.closeType):"CLOSE"===this.closeType&&c(),x()}}update(e){if(e.length!==this.controlPoints.length)throw new Error("The number of points changed. (Keep the length of the point array the same.)");L(this.controlPoints,e)||(this.controlPoints=e,this._buildVertexList())}move(e,t,r=null,i=!0,o=0){if(null===r&&3===this.dimension)throw new Error("To move a 3D curve, please specify (x, y, z).");{let n=[e,t];null!==r&&n.push(r);let s=[];for(let e=0;e<this.vertexListLen;e++)s.push(this.vertexList[e].slice());let h=new b(this.controlPoints,this.closeType,this.increment,this.dimension,s);for(let e=0;e<h.vertexListLen;e++)for(let t=0;t<h.dimension;t++)h.vertexList[e][t]+=n[t];return i&&h.draw(o),h}}shortest(e,t,r=0){let i,o=-1,n=0;for(let s of this.vertexList)-1===o?(o=this._distVertex(s,[e,t,r]),i=s):(n=this._distVertex(s,[e,t,r]),o>n&&(o=n,i=s));return i}}const L=(e,t)=>e.length===t.length&&e.every(((e,r)=>e===t[r]));return t})()));
3
3
  //# sourceMappingURL=p5.bezier.min.js.map
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  *
3
3
  * @license
4
- * p5bezier Version 0.3.0
4
+ * p5bezier Version 0.3.2
5
5
  * https://github.com/peilingjiang/p5.bezier
6
6
  *
7
7
  * Copyright 2018-2022 Peiling Jiang
@@ -1 +1 @@
1
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AAGC,GACP,OAANuD,GAAYE,EAAO5D,KAAK0D,GAE5B,IAAIG,EAAY,GAChB,IAAK,IAAIxD,EAAI,EAAGA,EAAIuB,KAAKK,cAAe5B,IACtCwD,EAAU7D,KAAK4B,KAAKI,WAAW3B,GAAGI,SACpC,IAAIqD,EAAc,IAAIhD,EACpBc,KAAKC,cACLD,KAAKnC,UACLmC,KAAKG,UACLH,KAAKE,UACL+B,GAGF,IAAK,IAAIxD,EAAI,EAAGA,EAAIyD,EAAY7B,cAAe5B,IAC7C,IAAK,IAAI0D,EAAI,EAAGA,EAAID,EAAYhC,UAAWiC,IACzCD,EAAY9B,WAAW3B,GAAG0D,IAAMH,EAAOG,GAM3C,OAHIJ,GACFG,EAAYrB,KAAKC,GAEZoB,GAIXE,SAASC,EAAIC,EAAIC,EAAK,GAIpB,IAEIC,EAFAC,GAAQ,EACVC,EAAS,EAEX,IAAK,IAAIlB,KAAKxB,KAAKI,YACH,IAAVqC,GACFA,EAAOzC,KAAKU,YAAYc,EAAG,CAACa,EAAIC,EAAIC,IACpCC,EAAYhB,IAEZkB,EAAS1C,KAAKU,YAAYc,EAAG,CAACa,EAAIC,EAAIC,IAClCE,EAAOC,IACTD,EAAOC,EACPF,EAAYhB,IAIlB,OAAOgB,GAOX,MAAMZ,EAAc,CAACzC,EAAGwD,IACtBxD,EAAEhB,SAAWwE,EAAExE,QAAUgB,EAAEyD,OAAM,CAACpB,EAAG/C,IAAM+C,IAAMmB,EAAElE,eLpbrD","sources":["webpack://p5bezier/webpack/universalModuleDefinition","webpack://p5bezier/webpack/bootstrap","webpack://p5bezier/webpack/runtime/define property getters","webpack://p5bezier/webpack/runtime/hasOwnProperty shorthand","webpack://p5bezier/webpack/runtime/make namespace object","webpack://p5bezier/./src/p5.bezier.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"p5bezier\"] = factory();\n\telse\n\t\troot[\"p5bezier\"] = factory();\n})(self, function() {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/*\np5.bezier library by Peiling Jiang\n2020\n*/\n\nconst p5bezierAccuracyListAll = [\n 0.2, 0.1, 0.05, 0.04, 0.02, 0.01, 0.008, 0.002, 0.001, 0.0005, 0.0001,\n]\n\nlet _canvas,\n _ctx,\n _dimension,\n _strict,\n _useP5,\n _beginPath,\n _moveTo,\n _lineTo,\n _closePath\n\nexport function initBezier(canvas, strictMode = false) {\n _canvas = canvas\n _ctx = _canvas.drawingContext\n\n // eslint-disable-next-line no-undef\n if (p5 && canvas instanceof p5.Graphics) {\n // p5 graphics\n _useP5 = true\n _dimension = _ctx.constructor.name === 'WebGLRenderingContext' ? 3 : 2\n\n _beginPath = _canvas.beginShape\n _moveTo = _canvas.vertex\n _lineTo = _canvas.vertex\n _closePath = _canvas.endShape\n // eslint-disable-next-line no-undef\n } else if ((p5 && canvas instanceof p5.Renderer) || canvas.drawingContext) {\n // p5 canvas or other canvas\n // eslint-disable-next-line no-undef\n if (!p5 || (p5 && !(canvas instanceof p5.Renderer))) {\n window.console.warn(\n '[p5.bezier] Support for non-p5 canvas is not tested.'\n )\n _dimension = canvas.isP3D ? 3 : 2\n } else {\n _dimension = _ctx.constructor.name === 'WebGLRenderingContext' ? 3 : 2\n }\n _useP5 = false\n _dimension = _ctx.constructor.name === 'WebGLRenderingContext' ? 3 : 2\n\n _beginPath = _ctx.beginPath.bind(_ctx)\n _moveTo = _ctx.moveTo.bind(_ctx)\n _lineTo = _ctx.lineTo.bind(_ctx)\n _closePath = _ctx.closePath.bind(_ctx)\n } else {\n throw new Error('[p5.bezier] Canvas is not supported.')\n }\n\n _strict = strictMode // Always check and throw errors or not\n}\n\nexport function newBezier(pointList, closeType = 'OPEN', accuracy = 7) {\n if (_strict && !Array.isArray(pointList))\n throw new Error(\n `[p5.bezier] newBezier() function expects an array, got ${typeof pointList}.`\n )\n\n // Define the increment of t based on accuracy\n const tIncrement = p5bezierAccuracyListAll[accuracy]\n\n if (_dimension !== 0) {\n // Check if all points are valid\n if (_strict)\n for (let point of pointList)\n if (!Array.isArray(pointList) || point.length !== _dimension)\n throw new Error(\n '[p5.bezier] One or more points in the array are not input correctly.'\n )\n\n // Add the first point as the last point to close the curve\n if (closeType === 'CLOSE') pointList.push(pointList[0])\n let p = pointList.length // pointList has p points for (p - 1) degree curves\n let n = p - 1\n\n _beginPath()\n _moveTo(...pointList[0])\n // Are we drawing 2D or 3D curves\n if (_dimension === 2) {\n // 2-Dimensional bezier curve\n let x, y, t, i\n for (t = 0; t <= 1; t += tIncrement) {\n x = 0\n y = 0\n for (i = 0; i <= n; i++) {\n // i point in pointList\n x +=\n (_helper_factorial(n) /\n (_helper_factorial(i) * _helper_factorial(n - i))) *\n Math.pow(1 - t, n - i) *\n Math.pow(t, i) *\n pointList[i][0]\n y +=\n (_helper_factorial(n) /\n (_helper_factorial(i) * _helper_factorial(n - i))) *\n Math.pow(1 - t, n - i) *\n Math.pow(t, i) *\n pointList[i][1]\n }\n _lineTo(x, y)\n }\n _lineTo(...pointList.slice(-1)[0])\n } else if (_dimension === 3) {\n // 3-Dimensional bezier curve\n let xyz = [0, 0, 0],\n t,\n i,\n d\n for (t = 0; t <= 1; t += tIncrement) {\n xyz = [0, 0, 0]\n for (i = 0; i <= n; i++) {\n for (d = 0; d < 3; d++) {\n xyz[d] +=\n (_helper_factorial(n) /\n (_helper_factorial(i) * _helper_factorial(n - i))) *\n Math.pow(1 - t, n - i) *\n Math.pow(t, i) *\n pointList[i][d]\n }\n }\n _lineTo(...xyz)\n }\n _lineTo(...pointList.slice(-1)[0])\n }\n\n if (_useP5) _closePath(closeType)\n else if (closeType === 'CLOSE') _closePath()\n else if (_strict && closeType !== 'OPEN')\n throw new Error(\n '[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.'\n )\n\n _helper_style()\n\n return\n }\n}\n\nexport function newBezierObj(pointList, closeType = 'OPEN', accuracy = 7) {\n // Define the increment of t based on accuracy\n const tIncrement = p5bezierAccuracyListAll[accuracy]\n\n if (_strict && !Array.isArray(pointList))\n throw new Error(\n `[p5.bezier] newBezierObj() function expects an array, got ${typeof pointList}.`\n )\n\n // Check if all points are valid\n if (_strict)\n for (let point of pointList)\n if (!Array.isArray(pointList) || point.length !== _dimension)\n throw new Error(\n '[p5.bezier] One or more points in the array are not input correctly.'\n )\n\n // All checks done\n let bObj = new BezierCurve(pointList, closeType, tIncrement, _dimension)\n return bObj\n}\n\nfunction _helper_factorial(a) {\n // Factorial function for binomial coefficient calculation\n return a > 1 ? a * _helper_factorial(a - 1) : 1\n}\n\nfunction _helper_dist() {\n if (arguments.length === 4)\n return Math.hypot(arguments[0] - arguments[2], arguments[1] - arguments[3])\n else if (arguments.length === 6)\n return Math.hypot(\n arguments[0] - arguments[3],\n arguments[1] - arguments[4],\n arguments[2] - arguments[5]\n )\n return 0\n}\n\nfunction _helper_style() {\n if (_canvas._doFill) _ctx.fill()\n if (_canvas._doStroke) _ctx.stroke()\n}\n\nclass BezierCurve {\n // Take pointList, closeType, tIncrement, bezierDimension into constructor\n constructor(pL, closeT, tI, bD, vL = null) {\n if (_strict && bD !== 2 && bD !== 3)\n throw new Error(\n `Dimension error. The bezier curve is ${bD}-dimensional and doesn't belong to our world.`\n )\n\n this.controlPoints = pL\n\n if (closeT === 'CLOSE') {\n this.controlPoints.push(pL[0])\n this.closeType = 'CLOSE'\n } else if (closeT === 'OPEN') {\n this.closeType = 'OPEN'\n } else {\n throw new Error(\n '[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.'\n )\n }\n\n this.dimension = bD\n this.increment = tI\n this.vertexList = []\n this.vertexListLen = 0\n this.p = this.controlPoints.length // Has p points for (p - 1) degree curves\n this.n = this.p - 1 // Degree\n // Calculate thr vertex\n if (vL === null) {\n this._buildVertexList()\n } else {\n this.vertexList = vL\n this.vertexListLen = this.vertexList.length\n }\n }\n\n _buildVertexList() {\n /*\n Return vertexList\n */\n this.vertexList = []\n if (this.dimension === 2) {\n // 2-Dimensional bezier curve\n let x, y, t, i\n for (t = 0; t <= 1; t += this.increment) {\n x = 0\n y = 0\n for (i = 0; i <= this.n; i++) {\n // i point in pointList\n x +=\n (_helper_factorial(this.n) /\n (_helper_factorial(i) * _helper_factorial(this.n - i))) *\n Math.pow(1 - t, this.n - i) *\n Math.pow(t, i) *\n this.controlPoints[i][0]\n y +=\n (_helper_factorial(this.n) /\n (_helper_factorial(i) * _helper_factorial(this.n - i))) *\n Math.pow(1 - t, this.n - i) *\n Math.pow(t, i) *\n this.controlPoints[i][1]\n }\n this.vertexList.push([x, y])\n }\n } else if (this.dimension === 3) {\n // 3-Dimensional bezier curve\n let xyz = [0, 0, 0],\n t,\n i,\n d\n for (t = 0; t <= 1; t += this.increment) {\n xyz[0] = 0\n xyz[1] = 0\n xyz[2] = 0\n for (i = 0; i <= this.n; i++) {\n for (d = 0; d < 3; d++) {\n xyz[d] +=\n (_helper_factorial(this.n) /\n (_helper_factorial(i) * _helper_factorial(this.n - i))) *\n Math.pow(1 - t, this.n - i) *\n Math.pow(t, i) *\n this.controlPoints[i][d]\n }\n }\n this.vertexList.push(xyz)\n }\n }\n // Ending fix\n this._addVertex(this.controlPoints.slice(-1)[0])\n\n this.dimension = this.vertexList[0].length // Update dimension\n this.vertexListLen = this.vertexList.length // Update vertexListLen\n return this.vertexList\n }\n\n _addVertex(vArray) {\n // vArray is an array of [x, y] position or [x, y, z] position\n if (this.dimension === 2 || this.dimension === 3) _lineTo(...vArray)\n else throw new Error('Vertices can only be in 2D or 3D space.')\n }\n\n _distVertex(vArray1, vArray2) {\n // Calculate the distance between\n // vertex_array_1 and vertex_array_2\n if (this.dimension === 2) {\n return _helper_dist(vArray1[0], vArray1[1], vArray2[0], vArray2[1])\n } else if (this.dimension === 3) {\n return _helper_dist(\n vArray1[0],\n vArray1[1],\n vArray1[2],\n vArray2[0],\n vArray2[1],\n vArray2[2]\n )\n }\n }\n\n draw(dash) {\n if (!dash) {\n _beginPath()\n for (let v of this.vertexList) {\n this._addVertex(v)\n }\n\n if (this.closeType === 'CLOSE') _ctx.closePath()\n\n if (_useP5) _closePath(this.closeType)\n else if (this.closeType === 'CLOSE') _closePath()\n\n _helper_style()\n } else if (\n Array.isArray(dash) &&\n dash.length === 2 &&\n this.increment <= 0.008\n ) {\n // Draw a dash curve\n let solidPart = Math.abs(dash[0]) // Length of one solid part\n let onePart = solidPart + Math.abs(dash[1]),\n nowLen = 0,\n modOnePart = 0\n let lastVertex = this.vertexList[0]\n let solid = true // true draw, false break\n\n _ctx.save() // push\n _ctx.fillStyle = 'rgba(0, 0, 0, 0)' // TODO: Enable fill\n _beginPath()\n _moveTo(...this.vertexList[0])\n for (let v = 1; v < this.vertexListLen; v++) {\n nowLen += this._distVertex(lastVertex, this.vertexList[v])\n modOnePart = nowLen % onePart\n if (modOnePart <= solidPart && solid) {\n this._addVertex(this.vertexList[v])\n } else if (modOnePart > solidPart && modOnePart <= onePart && solid) {\n // endShape()\n solid = false\n } else if (modOnePart <= solidPart && !solid) {\n _moveTo(...this.vertexList[v])\n solid = true\n }\n lastVertex = this.vertexList[v]\n }\n // if (solid) {\n // // Shape didn't end\n // endShape()\n // }\n _helper_style()\n _ctx.restore()\n } else if (this.increment > 0.008)\n throw new Error(\n 'Fidelity is too low for a dash line. It should be at least 6.'\n )\n else\n throw new Error(\n \"Your dash array input is not valid. Make sure it's an array of two numbers.\"\n )\n }\n\n update(newControlList) {\n /*\n Update the vertexList when control points change\n */\n if (newControlList.length !== this.controlPoints.length) {\n throw new Error(\n 'The number of points changed. (Keep the length of the point array the same.)'\n )\n } else if (equalArrays(this.controlPoints, newControlList)) {\n // Do we really need to update? No.\n // return ;\n } else {\n this.controlPoints = newControlList\n this._buildVertexList()\n }\n }\n\n move(x, y, z = null, toDraw = true, dash = 0) {\n /*\n Move the curve to another place\n Return a new object\n */\n if (z === null && this.dimension === 3) {\n // A 3D curve treated as 2D error\n throw new Error('To move a 3D curve, please specify (x, y, z).')\n } else {\n let toMove = [x, y]\n if (z !== null) toMove.push(z)\n // Copy to a new object\n let newCurveV = []\n for (let i = 0; i < this.vertexListLen; i++)\n newCurveV.push(this.vertexList[i].slice())\n let newCurveObj = new BezierCurve(\n this.controlPoints,\n this.closeType,\n this.increment,\n this.dimension,\n newCurveV\n )\n // Move\n for (let i = 0; i < newCurveObj.vertexListLen; i++) {\n for (let j = 0; j < newCurveObj.dimension; j++) {\n newCurveObj.vertexList[i][j] += toMove[j]\n }\n }\n if (toDraw) {\n newCurveObj.draw(dash)\n }\n return newCurveObj\n }\n }\n\n shortest(pX, pY, pZ = 0) {\n // Return the point on curve that is closest to the point outside\n // Always return array length of 3\n // Last position (z) be 0 for all 2D calculation\n let dMin = -1,\n nowMin = 0\n let minVertex\n for (let v of this.vertexList) {\n if (dMin === -1) {\n dMin = this._distVertex(v, [pX, pY, pZ])\n minVertex = v\n } else {\n nowMin = this._distVertex(v, [pX, pY, pZ])\n if (dMin > nowMin) {\n dMin = nowMin\n minVertex = v\n }\n }\n }\n return minVertex // An array of vertex position\n }\n}\n\n/* --------------------------------- HELPERS -------------------------------- */\n\n// https://www.30secondsofcode.org/blog/s/javascript-array-comparison\nconst equalArrays = (a, b) =>\n a.length === b.length && a.every((v, i) => v === b[i])\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","p5bezierAccuracyListAll","_canvas","_ctx","_dimension","_strict","_useP5","_beginPath","_moveTo","_lineTo","_closePath","initBezier","canvas","strictMode","drawingContext","p5","Graphics","constructor","name","beginShape","vertex","endShape","Renderer","Error","window","console","warn","isP3D","beginPath","bind","moveTo","lineTo","closePath","newBezier","pointList","closeType","accuracy","Array","isArray","tIncrement","point","length","push","n","x","y","t","i","_helper_factorial","Math","pow","slice","d","xyz","_helper_style","newBezierObj","BezierCurve","a","_helper_dist","arguments","hypot","_doFill","fill","_doStroke","stroke","pL","closeT","tI","bD","vL","this","controlPoints","dimension","increment","vertexList","vertexListLen","p","_buildVertexList","_addVertex","vArray","_distVertex","vArray1","vArray2","draw","dash","solidPart","abs","onePart","nowLen","modOnePart","lastVertex","solid","save","fillStyle","v","restore","update","newControlList","equalArrays","move","z","toDraw","toMove","newCurveV","newCurveObj","j","shortest","pX","pY","pZ","minVertex","dMin","nowMin","b","every"],"sourceRoot":""}
1
+ {"version":3,"file":"p5.bezier.min.js","mappings":";CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAkB,SAAID,IAEtBD,EAAe,SAAIC,GACpB,CATD,CASGK,MAAM,IACT,mBCTA,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,E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ACzCD,EAAY9B,WAAW3B,GAAG0D,IAAMH,EAAOG,GAM3C,OAHIJ,GACFG,EAAYrB,KAAKC,GAEZoB,CACT,CACF,CAEAE,SAASC,EAAIC,EAAIC,EAAK,GAIpB,IAEIC,EAFAC,GAAQ,EACVC,EAAS,EAEX,IAAK,IAAIlB,KAAKxB,KAAKI,YACH,IAAVqC,GACFA,EAAOzC,KAAKU,YAAYc,EAAG,CAACa,EAAIC,EAAIC,IACpCC,EAAYhB,IAEZkB,EAAS1C,KAAKU,YAAYc,EAAG,CAACa,EAAIC,EAAIC,IAClCE,EAAOC,IACTD,EAAOC,EACPF,EAAYhB,IAIlB,OAAOgB,CACT,EAMF,MAAMZ,EAAc,CAACzC,EAAGwD,IACtBxD,EAAEhB,SAAWwE,EAAExE,QAAUgB,EAAEyD,OAAM,CAACpB,EAAG/C,IAAM+C,IAAMmB,EAAElE,eLpbrD","sources":["webpack://p5bezier/webpack/universalModuleDefinition","webpack://p5bezier/webpack/bootstrap","webpack://p5bezier/webpack/runtime/define property getters","webpack://p5bezier/webpack/runtime/hasOwnProperty shorthand","webpack://p5bezier/webpack/runtime/make namespace object","webpack://p5bezier/./src/p5.bezier.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"p5bezier\"] = factory();\n\telse\n\t\troot[\"p5bezier\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/*\np5.bezier library by Peiling Jiang\n2020\n*/\n\nconst p5bezierAccuracyListAll = [\n 0.2, 0.1, 0.05, 0.04, 0.02, 0.01, 0.008, 0.002, 0.001, 0.0005, 0.0001,\n]\n\nlet _canvas,\n _ctx,\n _dimension,\n _strict,\n _useP5,\n _beginPath,\n _moveTo,\n _lineTo,\n _closePath\n\nexport function initBezier(canvas, strictMode = false) {\n _canvas = canvas\n _ctx = _canvas.drawingContext\n\n // eslint-disable-next-line no-undef\n if (p5 && canvas instanceof p5.Graphics) {\n // p5 graphics\n _useP5 = true\n _dimension = _ctx.constructor.name === 'WebGLRenderingContext' ? 3 : 2\n\n _beginPath = _canvas.beginShape\n _moveTo = _canvas.vertex\n _lineTo = _canvas.vertex\n _closePath = _canvas.endShape\n // eslint-disable-next-line no-undef\n } else if ((p5 && canvas instanceof p5.Renderer) || canvas.drawingContext) {\n // p5 canvas or other canvas\n // eslint-disable-next-line no-undef\n if (!p5 || (p5 && !(canvas instanceof p5.Renderer))) {\n window.console.warn(\n '[p5.bezier] Support for non-p5 canvas is not tested.'\n )\n _dimension = canvas.isP3D ? 3 : 2\n } else {\n _dimension = _ctx.constructor.name === 'WebGLRenderingContext' ? 3 : 2\n }\n _useP5 = false\n _dimension = _ctx.constructor.name === 'WebGLRenderingContext' ? 3 : 2\n\n _beginPath = _ctx.beginPath.bind(_ctx)\n _moveTo = _ctx.moveTo.bind(_ctx)\n _lineTo = _ctx.lineTo.bind(_ctx)\n _closePath = _ctx.closePath.bind(_ctx)\n } else {\n throw new Error('[p5.bezier] Canvas is not supported.')\n }\n\n _strict = strictMode // Always check and throw errors or not\n}\n\nexport function newBezier(pointList, closeType = 'OPEN', accuracy = 6) {\n if (_strict && !Array.isArray(pointList))\n throw new Error(\n `[p5.bezier] newBezier() function expects an array, got ${typeof pointList}.`\n )\n\n // Define the increment of t based on accuracy\n const tIncrement = p5bezierAccuracyListAll[accuracy]\n\n if (_dimension !== 0) {\n // Check if all points are valid\n if (_strict)\n for (let point of pointList)\n if (!Array.isArray(pointList) || point.length !== _dimension)\n throw new Error(\n '[p5.bezier] One or more points in the array are not input correctly.'\n )\n\n // Add the first point as the last point to close the curve\n if (closeType === 'CLOSE') pointList.push(pointList[0])\n let p = pointList.length // pointList has p points for (p - 1) degree curves\n let n = p - 1\n\n _beginPath()\n _moveTo(...pointList[0])\n // Are we drawing 2D or 3D curves\n if (_dimension === 2) {\n // 2-Dimensional bezier curve\n let x, y, t, i\n for (t = 0; t <= 1; t += tIncrement) {\n x = 0\n y = 0\n for (i = 0; i <= n; i++) {\n // i point in pointList\n x +=\n (_helper_factorial(n) /\n (_helper_factorial(i) * _helper_factorial(n - i))) *\n Math.pow(1 - t, n - i) *\n Math.pow(t, i) *\n pointList[i][0]\n y +=\n (_helper_factorial(n) /\n (_helper_factorial(i) * _helper_factorial(n - i))) *\n Math.pow(1 - t, n - i) *\n Math.pow(t, i) *\n pointList[i][1]\n }\n _lineTo(x, y)\n }\n _lineTo(...pointList.slice(-1)[0])\n } else if (_dimension === 3) {\n // 3-Dimensional bezier curve\n let xyz = [0, 0, 0],\n t,\n i,\n d\n for (t = 0; t <= 1; t += tIncrement) {\n xyz = [0, 0, 0]\n for (i = 0; i <= n; i++) {\n for (d = 0; d < 3; d++) {\n xyz[d] +=\n (_helper_factorial(n) /\n (_helper_factorial(i) * _helper_factorial(n - i))) *\n Math.pow(1 - t, n - i) *\n Math.pow(t, i) *\n pointList[i][d]\n }\n }\n _lineTo(...xyz)\n }\n _lineTo(...pointList.slice(-1)[0])\n }\n\n if (_useP5) _closePath(closeType)\n else if (closeType === 'CLOSE') _closePath()\n else if (_strict && closeType !== 'OPEN')\n throw new Error(\n '[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.'\n )\n\n _helper_style()\n\n return\n }\n}\n\nexport function newBezierObj(pointList, closeType = 'OPEN', accuracy = 6) {\n // Define the increment of t based on accuracy\n const tIncrement = p5bezierAccuracyListAll[accuracy]\n\n if (_strict && !Array.isArray(pointList))\n throw new Error(\n `[p5.bezier] newBezierObj() function expects an array, got ${typeof pointList}.`\n )\n\n // Check if all points are valid\n if (_strict)\n for (let point of pointList)\n if (!Array.isArray(pointList) || point.length !== _dimension)\n throw new Error(\n '[p5.bezier] One or more points in the array are not input correctly.'\n )\n\n // All checks done\n let bObj = new BezierCurve(pointList, closeType, tIncrement, _dimension)\n return bObj\n}\n\nfunction _helper_factorial(a) {\n // Factorial function for binomial coefficient calculation\n return a > 1 ? a * _helper_factorial(a - 1) : 1\n}\n\nfunction _helper_dist() {\n if (arguments.length === 4)\n return Math.hypot(arguments[0] - arguments[2], arguments[1] - arguments[3])\n else if (arguments.length === 6)\n return Math.hypot(\n arguments[0] - arguments[3],\n arguments[1] - arguments[4],\n arguments[2] - arguments[5]\n )\n return 0\n}\n\nfunction _helper_style() {\n if (_canvas._doFill) _ctx.fill()\n if (_canvas._doStroke) _ctx.stroke()\n}\n\nclass BezierCurve {\n // Take pointList, closeType, tIncrement, bezierDimension into constructor\n constructor(pL, closeT, tI, bD, vL = null) {\n if (_strict && bD !== 2 && bD !== 3)\n throw new Error(\n `Dimension error. The bezier curve is ${bD}-dimensional and doesn't belong to our world.`\n )\n\n this.controlPoints = pL\n\n if (closeT === 'CLOSE') {\n this.controlPoints.push(pL[0])\n this.closeType = 'CLOSE'\n } else if (closeT === 'OPEN') {\n this.closeType = 'OPEN'\n } else {\n throw new Error(\n '[p5.bezier] Close type error. A bezier curve can only be either OPEN or CLOSE.'\n )\n }\n\n this.dimension = bD\n this.increment = tI\n this.vertexList = []\n this.vertexListLen = 0\n this.p = this.controlPoints.length // Has p points for (p - 1) degree curves\n this.n = this.p - 1 // Degree\n // Calculate thr vertex\n if (vL === null) {\n this._buildVertexList()\n } else {\n this.vertexList = vL\n this.vertexListLen = this.vertexList.length\n }\n }\n\n _buildVertexList() {\n /*\n Return vertexList\n */\n this.vertexList = []\n if (this.dimension === 2) {\n // 2-Dimensional bezier curve\n let x, y, t, i\n for (t = 0; t <= 1; t += this.increment) {\n x = 0\n y = 0\n for (i = 0; i <= this.n; i++) {\n // i point in pointList\n x +=\n (_helper_factorial(this.n) /\n (_helper_factorial(i) * _helper_factorial(this.n - i))) *\n Math.pow(1 - t, this.n - i) *\n Math.pow(t, i) *\n this.controlPoints[i][0]\n y +=\n (_helper_factorial(this.n) /\n (_helper_factorial(i) * _helper_factorial(this.n - i))) *\n Math.pow(1 - t, this.n - i) *\n Math.pow(t, i) *\n this.controlPoints[i][1]\n }\n this.vertexList.push([x, y])\n }\n } else if (this.dimension === 3) {\n // 3-Dimensional bezier curve\n let xyz = [0, 0, 0],\n t,\n i,\n d\n for (t = 0; t <= 1; t += this.increment) {\n xyz[0] = 0\n xyz[1] = 0\n xyz[2] = 0\n for (i = 0; i <= this.n; i++) {\n for (d = 0; d < 3; d++) {\n xyz[d] +=\n (_helper_factorial(this.n) /\n (_helper_factorial(i) * _helper_factorial(this.n - i))) *\n Math.pow(1 - t, this.n - i) *\n Math.pow(t, i) *\n this.controlPoints[i][d]\n }\n }\n this.vertexList.push(xyz)\n }\n }\n // Ending fix\n this._addVertex(this.controlPoints.slice(-1)[0])\n\n this.dimension = this.vertexList[0].length // Update dimension\n this.vertexListLen = this.vertexList.length // Update vertexListLen\n return this.vertexList\n }\n\n _addVertex(vArray) {\n // vArray is an array of [x, y] position or [x, y, z] position\n if (this.dimension === 2 || this.dimension === 3) _lineTo(...vArray)\n else throw new Error('Vertices can only be in 2D or 3D space.')\n }\n\n _distVertex(vArray1, vArray2) {\n // Calculate the distance between\n // vertex_array_1 and vertex_array_2\n if (this.dimension === 2) {\n return _helper_dist(vArray1[0], vArray1[1], vArray2[0], vArray2[1])\n } else if (this.dimension === 3) {\n return _helper_dist(\n vArray1[0],\n vArray1[1],\n vArray1[2],\n vArray2[0],\n vArray2[1],\n vArray2[2]\n )\n }\n }\n\n draw(dash) {\n if (!dash) {\n _beginPath()\n for (let v of this.vertexList) {\n this._addVertex(v)\n }\n\n if (this.closeType === 'CLOSE') _ctx.closePath()\n\n if (_useP5) _closePath(this.closeType)\n else if (this.closeType === 'CLOSE') _closePath()\n\n _helper_style()\n } else if (\n Array.isArray(dash) &&\n dash.length === 2 &&\n this.increment <= 0.008\n ) {\n // Draw a dash curve\n let solidPart = Math.abs(dash[0]) // Length of one solid part\n let onePart = solidPart + Math.abs(dash[1]),\n nowLen = 0,\n modOnePart = 0\n let lastVertex = this.vertexList[0]\n let solid = true // true draw, false break\n\n _ctx.save() // push\n _ctx.fillStyle = 'rgba(0, 0, 0, 0)' // TODO: Enable fill\n _beginPath()\n _moveTo(...this.vertexList[0])\n for (let v = 1; v < this.vertexListLen; v++) {\n nowLen += this._distVertex(lastVertex, this.vertexList[v])\n modOnePart = nowLen % onePart\n if (modOnePart <= solidPart && solid) {\n this._addVertex(this.vertexList[v])\n } else if (modOnePart > solidPart && modOnePart <= onePart && solid) {\n // endShape()\n solid = false\n } else if (modOnePart <= solidPart && !solid) {\n _moveTo(...this.vertexList[v])\n solid = true\n }\n lastVertex = this.vertexList[v]\n }\n // if (solid) {\n // // Shape didn't end\n // endShape()\n // }\n _helper_style()\n _ctx.restore()\n } else if (this.increment > 0.008)\n throw new Error(\n 'Fidelity is too low for a dash line. It should be at least 6.'\n )\n else\n throw new Error(\n \"Your dash array input is not valid. Make sure it's an array of two numbers.\"\n )\n }\n\n update(newControlList) {\n /*\n Update the vertexList when control points change\n */\n if (newControlList.length !== this.controlPoints.length) {\n throw new Error(\n 'The number of points changed. (Keep the length of the point array the same.)'\n )\n } else if (equalArrays(this.controlPoints, newControlList)) {\n // Do we really need to update? No.\n // return ;\n } else {\n this.controlPoints = newControlList\n this._buildVertexList()\n }\n }\n\n move(x, y, z = null, toDraw = true, dash = 0) {\n /*\n Move the curve to another place\n Return a new object\n */\n if (z === null && this.dimension === 3) {\n // A 3D curve treated as 2D error\n throw new Error('To move a 3D curve, please specify (x, y, z).')\n } else {\n let toMove = [x, y]\n if (z !== null) toMove.push(z)\n // Copy to a new object\n let newCurveV = []\n for (let i = 0; i < this.vertexListLen; i++)\n newCurveV.push(this.vertexList[i].slice())\n let newCurveObj = new BezierCurve(\n this.controlPoints,\n this.closeType,\n this.increment,\n this.dimension,\n newCurveV\n )\n // Move\n for (let i = 0; i < newCurveObj.vertexListLen; i++) {\n for (let j = 0; j < newCurveObj.dimension; j++) {\n newCurveObj.vertexList[i][j] += toMove[j]\n }\n }\n if (toDraw) {\n newCurveObj.draw(dash)\n }\n return newCurveObj\n }\n }\n\n shortest(pX, pY, pZ = 0) {\n // Return the point on curve that is closest to the point outside\n // Always return array length of 3\n // Last position (z) be 0 for all 2D calculation\n let dMin = -1,\n nowMin = 0\n let minVertex\n for (let v of this.vertexList) {\n if (dMin === -1) {\n dMin = this._distVertex(v, [pX, pY, pZ])\n minVertex = v\n } else {\n nowMin = this._distVertex(v, [pX, pY, pZ])\n if (dMin > nowMin) {\n dMin = nowMin\n minVertex = v\n }\n }\n }\n return minVertex // An array of vertex position\n }\n}\n\n/* --------------------------------- HELPERS -------------------------------- */\n\n// https://www.30secondsofcode.org/blog/s/javascript-array-comparison\nconst equalArrays = (a, b) =>\n a.length === b.length && a.every((v, i) => v === b[i])\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","p5bezierAccuracyListAll","_canvas","_ctx","_dimension","_strict","_useP5","_beginPath","_moveTo","_lineTo","_closePath","initBezier","canvas","strictMode","drawingContext","p5","Graphics","constructor","name","beginShape","vertex","endShape","Renderer","Error","window","console","warn","isP3D","beginPath","bind","moveTo","lineTo","closePath","newBezier","pointList","closeType","accuracy","Array","isArray","tIncrement","point","length","push","n","x","y","t","i","_helper_factorial","Math","pow","slice","d","xyz","_helper_style","newBezierObj","BezierCurve","a","_helper_dist","arguments","hypot","_doFill","fill","_doStroke","stroke","pL","closeT","tI","bD","vL","this","controlPoints","dimension","increment","vertexList","vertexListLen","p","_buildVertexList","_addVertex","vArray","_distVertex","vArray1","vArray2","draw","dash","solidPart","abs","onePart","nowLen","modOnePart","lastVertex","solid","save","fillStyle","v","restore","update","newControlList","equalArrays","move","z","toDraw","toMove","newCurveV","newCurveObj","j","shortest","pX","pY","pZ","minVertex","dMin","nowMin","b","every"],"sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "p5bezier",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Bezier library for canvas-based graphics on the web, built to work with p5.js.",
5
5
  "main": "lib/p5.bezier.min.js",
6
6
  "keywords": [
@@ -19,13 +19,13 @@
19
19
  },
20
20
  "homepage": "https://github.com/peilingjiang/p5.bezier#readme",
21
21
  "devDependencies": {
22
- "eslint": "^8.9.0",
23
- "husky": "^7.0.4",
24
- "lint-staged": "^12.3.4",
25
- "prettier": "^2.5.1",
26
- "terser-webpack-plugin": "^5.3.1",
27
- "webpack": "^5.69.1",
28
- "webpack-cli": "^4.9.2"
22
+ "eslint": "^8.20.0",
23
+ "husky": "^8.0.1",
24
+ "lint-staged": "^13.0.3",
25
+ "prettier": "^2.7.1",
26
+ "terser-webpack-plugin": "^5.3.3",
27
+ "webpack": "^5.73.0",
28
+ "webpack-cli": "^4.10.0"
29
29
  },
30
30
  "scripts": {
31
31
  "format": "prettier --write \"**/*.{js,json,md,html,css}\"",