Skip to content

Commit

Permalink
Close #5 correct indication of East direction
Browse files Browse the repository at this point in the history
  • Loading branch information
bobboteck committed Nov 18, 2019
1 parent 9d4c482 commit bb87400
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A simple JoyStick for web application that use HTML5, Canvas and JavaScript. JQu
You can simply add a JoyStick in your HTML5 page, base configuration is ready for use it.
Developed for Web Remote Control of Robot, the JoyStick can be used for all other scope.

**Actual release version is 1.1.2**
**Actual release version is 1.1.3**

Using appropriate methods that the object provides, you can know the position of the Stick is located.
The methods available are:
Expand Down
5 changes: 3 additions & 2 deletions joy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* Name : joy.js
* @author : Roberto D'Amico (Bobboteck)
* Last modified : 12.11.2019
* Revision : 1.1.2
* 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
*
Expand Down
7 changes: 4 additions & 3 deletions joy.min.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* Name : joy.js
* @author : Roberto D'Amico (Bobboteck)
* Last modified : 12.11.2019
* Revision : 1.1.2
* 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
*
Expand All @@ -31,4 +32,4 @@
* 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,S=-1*L,W=u.height/10,k=-1*W,E=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(),E<g&&(E=w),E+g>u.width&&(E=u.width-w),G<g&&(G=w),G+g>u.height&&(G=u.height-w),s.arc(E,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&&(E=t.touches[0].pageX,G=t.touches[0].pageY,E-=u.offsetLeft,G-=u.offsetTop,s.clearRect(0,0,u.width,u.height),x(),y())},!1),u.addEventListener("touchend",function(t){f=0,E=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&&(E=t.pageX,G=t.pageY,E-=u.offsetLeft,G-=u.offsetTop,s.clearRect(0,0,u.width,u.height),x(),y())},!1),u.addEventListener("mouseup",function(t){f=0,E=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 E},this.GetPosY=function(){return G},this.GetX=function(){return((E-m)/w*100).toFixed()},this.GetY=function(){return((G-p)/w*100*-1).toFixed()},this.GetDir=function(){var t="",e=E-m,i=G-p;return i>=k&&i<=W&&(t="C"),i<k&&(t="N"),i>W&&(t="S"),e<S&&("C"==t?t="W":t+="W"),e>L&&("C"==t?t="W":t+="E"),t}};
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}};

0 comments on commit bb87400

Please sign in to comment.