NoNameCracksInc

Triangle

Sep 18th, 2015
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <body>
  5.  
  6. <canvas id='paper'></canvas>
  7.  
  8. <script>
  9.  
  10. var paper = document.getElementById('paper');
  11. paper.width = window.innerWidth;
  12. paper.height = window.innerHeight;
  13. paper.style.position = 'absolute';paper.style.left = 0;paper.style.top = 0;
  14.  
  15. document.body.onmousemove = function(e)
  16. {
  17.  
  18. paper.width = paper.width;
  19. var x = e.pageX;
  20. var y = e.pageY;
  21.  
  22. var ctx = paper.getContext('2d');
  23.  
  24. ctx.lineWidth = 1;
  25. ctx.beginPath();
  26.  
  27. ctx.moveTo(50,window.innerHeight/2);
  28. ctx.lineTo(x,y);
  29. ctx.moveTo(x,y);
  30. ctx.lineTo(e.pageX,window.innerHeight/2);
  31. ctx.moveTo(e.pageX,window.innerHeight/2);
  32. ctx.lineTo(50,window.innerHeight/2);
  33. ctx.moveTo(50,window.innerHeight/2);
  34.  
  35. var x = e.pageX - 50;
  36. var y = window.innerHeight/2 - e.pageY;
  37. var angle = Math.abs( Math.atan(y/x)*180/Math.PI );
  38.  
  39. ctx.font = '15px Calibri';
  40. ctx.fillStyle='blue';
  41. ctx.fillText(Math.round(angle)+'°',20,window.innerHeight/2);
  42. ctx.fillText((180-90-Math.round(angle))+'°',e.pageX+15,e.pageY);
  43.  
  44. ctx.stroke();
  45. }
  46.  
  47. </script>
  48.  
  49. </body>
  50.  
  51. </html>
Advertisement
Add Comment
Please, Sign In to add comment