text: /*
   * Name          : joy.js
   * @author       : Roberto D'Amico (Bobboteck)
   * Last modified : 18.11.2019
   * Revision      : 1.1.3
   *
   * Modification History:
   * Date         Version     Modified By		Description
   * 2019-11-18	1.1.3		Roberto D'Amico	Close #5 correct indication of East direction
   * 2019-11-12   1.1.2       Roberto D'Amico Removed Fix #4 incorrectly introduced and restored operation with touch devices
   * 2019-11-12   1.1.1       Roberto D'Amico Fixed Issue #4 - Now JoyStick work in any position in the page, not only at 0,0
   * 
   * The MIT License (MIT)
   *
   * Copyright (c) 2015 Roberto D'Amico (Bobboteck)
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   * copies of the Software, and to permit persons to whom the Software is
   * furnished to do so, subject to the following conditions:
   * 
   * The above copyright notice and this permission notice shall be included in all
   * copies or substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   * SOFTWARE.
   */
  var JoyStick=function(t,e){var i=void 0===(e=e||{}).title?"joystick":e.title,n=void 0===e.width?0:e.width,o=void 0===e.height?0:e.height,h=void 0===e.internalFillColor?"#00AA00":e.internalFillColor,r=void 0===e.internalLineWidth?2:e.internalLineWidth,d=void 0===e.internalStrokeColor?"#003300":e.internalStrokeColor,a=void 0===e.externalLineWidth?2:e.externalLineWidth,l=void 0===e.externalStrokeColor?"#008000":e.externalStrokeColor,c=document.getElementById(t),u=document.createElement("canvas");u.id=i,0==n&&(n=c.clientWidth),0==o&&(o=c.clientHeight),u.width=n,u.height=o,c.appendChild(u);var s=u.getContext("2d"),f=0,v=2*Math.PI,g=(u.width-110)/2,w=g+5,C=g+30,m=u.width/2,p=u.height/2,L=u.width/10,E=-1*L,S=u.height/10,k=-1*S,W=m,G=p;function x(){s.beginPath(),s.arc(m,p,C,0,v,!1),s.lineWidth=a,s.strokeStyle=l,s.stroke()}function y(){s.beginPath(),W<g&&(W=w),W+g>u.width&&(W=u.width-w),G<g&&(G=w),G+g>u.height&&(G=u.height-w),s.arc(W,G,g,0,v,!1);var t=s.createRadialGradient(m,p,5,m,p,200);t.addColorStop(0,h),t.addColorStop(1,d),s.fillStyle=t,s.fill(),s.lineWidth=r,s.strokeStyle=d,s.stroke()}"ontouchstart"in document.documentElement?(u.addEventListener("touchstart",function(t){f=1},!1),u.addEventListener("touchmove",function(t){t.preventDefault(),1==f&&(W=t.touches[0].pageX,G=t.touches[0].pageY,W-=u.offsetLeft,G-=u.offsetTop,s.clearRect(0,0,u.width,u.height),x(),y())},!1),u.addEventListener("touchend",function(t){f=0,W=m,G=p,s.clearRect(0,0,u.width,u.height),x(),y()},!1)):(u.addEventListener("mousedown",function(t){f=1},!1),u.addEventListener("mousemove",function(t){1==f&&(W=t.pageX,G=t.pageY,W-=u.offsetLeft,G-=u.offsetTop,s.clearRect(0,0,u.width,u.height),x(),y())},!1),u.addEventListener("mouseup",function(t){f=0,W=m,G=p,s.clearRect(0,0,u.width,u.height),x(),y()},!1)),x(),y(),this.GetWidth=function(){return u.width},this.GetHeight=function(){return u.height},this.GetPosX=function(){return W},this.GetPosY=function(){return G},this.GetX=function(){return((W-m)/w*100).toFixed()},this.GetY=function(){return((G-p)/w*100*-1).toFixed()},this.GetDir=function(){var t="",e=W-m,i=G-p;return i>=k&&i<=S&&(t="C"),i<k&&(t="N"),i>S&&(t="S"),e<E&&("C"==t?t="W":t+="W"),e>L&&("C"==t?t="E":t+="E"),t}};