Advertisement
Guest User

Untitled

a guest
May 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. /*Application Scripts*/
  2. function init(){
  3. "use strict";
  4. var el = document.getElementById('myCanvas');
  5. var ctx = el.getContext('2d');
  6.  
  7. var butLarge = document.getElementById('buttonLarge');
  8. var butSmall = document.getElementById('buttonSmall');
  9.  
  10.  
  11. el.width=window.innerWidth;
  12. el.height=window.innerHeight;
  13.  
  14. ctx.lineWidth = 5;
  15. ctx.lineJoin = ctx.lineCap = 'round';
  16. ctx.shadowBlur = 3.5;
  17. ctx.shadowColor = 'rgb(0, 0, 0)';
  18. ctx.shadowOffsetX = (ctx.shadowOffsetX) *(.5);
  19.  
  20. var isDrawing, points = [ ];
  21.  
  22. el.onmousedown = function(e) {
  23. isDrawing = true;
  24. points.push({ x: e.clientX, y: e.clientY });
  25.  
  26. };
  27.  
  28. el.onmousemove = function(e) {
  29. if (!isDrawing) return;
  30.  
  31. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  32. points.push({ x: e.clientX, y: e.clientY });
  33.  
  34. ctx.beginPath();
  35. ctx.moveTo(points[0].x, points[0].y);
  36. ctx.lineTo(points[points.length-1].x, points[points.length-1].y); //draws line to last point
  37. ctx.stroke();
  38.  
  39. };
  40.  
  41. el.onmouseup = function() {
  42. isDrawing = false;
  43. points.length = 0;
  44. };
  45.  
  46. function showCo_Ord(mm) {
  47. canvas_X = mm.pageX;
  48. canvas_Y = mm.pageY;
  49. window.alert("X : "+canvas_X+" Y : "+canvas_Y);
  50. }
  51. // a check to make sure that the program is responding
  52.  
  53. butLarge.onmousedown = function() {
  54. ctx.lineWidth = ctx.lineWidth + 2;
  55. }
  56. butSmall.onmousedown = function() {
  57. ctx.lineWidth = ctx.lineWidth - 2;
  58. }
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement