-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTortuga.min.js
1 lines (1 loc) · 4.52 KB
/
Tortuga.min.js
1
!function(t,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define("Tortuga",[],i):"object"==typeof exports?exports.Tortuga=i():t.Tortuga=i()}(this,function(){return function(t){function i(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}var e={};return i.m=t,i.c=e,i.i=function(t){return t},i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},i.p="",i(i.s=1)}([function(t,i,e){"use strict";var n=[0,0,0],o=[0,0,255],s=[0,255,0],r=[0,255,255],a=[255,0,0],h=[255,0,255],c=[255,255,0],u=[255,255,255],l=[155,96,59],f=[255,149,119],p=[34,139,34],v=[127,255,212],d=[250,128,114],g=[128,0,128],y=[255,163,0],x=[183,183,183],k=[n,o,s,r,a,h,c,u,l,f,p,v,d,g,y,x],b=function(t,i,e,n){return void 0===i?"rgb("+u.join(",")+")":void 0!==i&&void 0!==e&&void 0!==n?"rgb("+i+","+e+","+n+")":isNaN(parseInt(i,10))?i:"rgb("+t[parseInt(i,10)%t.length].join(",")+")"};t.exports={DEFAULT_PALETTE:k,getColorString:b}},function(t,i,e){"use strict";function n(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}var o=function(){function t(t,i){for(var e=0;e<i.length;e++){var n=i[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(i,e,n){return e&&t(i.prototype,e),n&&t(i,n),i}}(),s=e(0),r=s.DEFAULT_PALETTE,a=s.getColorString,h=7,c=function(t){return parseInt(t,10)},u=function(){function t(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"#tortuga",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:100;n(this,t);try{this.ctx=document.querySelector(i).getContext("2d")}catch(t){throw Error("The selector `"+i+"` matched no canvas element.")}this.position=[c(e),c(o)],this.length=c(s),this.direction=0,this._penDown=!0,this.palette=r,this.ctx.lineCap="round",this.background(0),this.penColor="",this.color(h),this.size(1),this.fixAxis(),this.clean(),this.begin()}return o(t,[{key:"fixAxis",value:function(){this.ctx.setTransform(1,0,0,1,0,0),this.ctx.translate(this.ctx.canvas.width/2,this.ctx.canvas.height/2),this.ctx.scale(1,-1)}},{key:"clean",value:function(){var t=this.ctx.canvas.height,i=this.ctx.canvas.width;this.ctx.clearRect(-1*i/2,-1*t/2,i,t)}},{key:"reset",value:function(){this.home(),this.clean(),this.begin()}},{key:"begin",value:function(){this.ctx.beginPath(),this.ctx.moveTo(this.position[0],this.position[1])}},{key:"drawPath",value:function(){this.ctx.stroke(),this.begin()}},{key:"background",value:function(t,i,e){this.ctx.canvas.style.backgroundColor=a(this.palette,t,i,e)}},{key:"color",value:function(t,i,e){this.penColor=a(this.palette,t,i,e),this.ctx.strokeStyle=this.penColor,this.drawPath()}},{key:"rainbow",value:function(t,i){var e=c(t),n=c(i);this.color("hsl("+Math.ceil(e/n*360)+", 100%, 50%)")}},{key:"size",value:function(t){this.penSize=parseFloat(t),this.ctx.lineWidth=this.penSize}},{key:"penUp",value:function(){this.drawPath(),this._penDown=!1}},{key:"penDown",value:function(){this._penDown=!0}},{key:"isPenDown",value:function(){return this._penDown}},{key:"setXY",value:function(t,i){this.position=[c(t),c(i)],this.isPenDown()?this.ctx.lineTo(this.position[0],this.position[1]):this.ctx.moveTo(this.position[0],this.position[1])}},{key:"setX",value:function(t){this.setXY(c(t),this.position[1])}},{key:"setY",value:function(t){this.setXY(this.position[0],c(t))}},{key:"home",value:function(){this.setXY(0,0),this.setHeading(0)}},{key:"forward",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.length,i=c(t),e=this.position[0],n=this.position[1],o=-1*this.direction+90;o=Math.PI*o/180,e+=Math.round(Math.cos(o)*i),n+=Math.round(Math.sin(o)*i),this.setXY(e,n)}},{key:"back",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.length;this.direction-=180,this.forward(c(t)),this.direction+=180}},{key:"right",value:function(t){this.direction=(this.direction+c(t))%360}},{key:"left",value:function(t){this.right(-1*c(t))}},{key:"setHeading",value:function(t){this.direction=c(t)%360}},{key:"towards",value:function(t,i){var e=[c(t)-this.position[0],c(i)-this.position[1]];return 180*Math.atan2(e[0],e[1])/Math.PI}}]),t}();t.exports=u}])});