Guest User

Untitled

a guest
Jun 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. var ctx = null;
  2. var canvas = null;
  3. var mousedownX = 0;
  4. var mousedownY = 0;
  5. var mouseupX = 0;
  6. var mouseupY = 0;
  7. var debugtxt = "";
  8. var mouseisup = true;
  9.  
  10. $(document).ready(function () {
  11. window.setInterval(loop, dt * 1000);
  12.  
  13. $(document).mousedown(function (e) {
  14. if (e.which == 1) {
  15. var offset = $("#canvas").offset();
  16. mousedownX = Math.floor(e.pageX - offset.left);
  17. mousedownY = Math.floor(e.pageY - offset.top);
  18. mouseisup = false;
  19. mouseDown();
  20. //debugtxt = offset.left + " " + offset.top;
  21. }
  22. });
  23. $(document).mouseup(function (e) {
  24. if (e.which == 1) {
  25. var offset = $("#canvas").offset();
  26. mouseupX = Math.floor(e.pageX - offset.left);
  27. mouseupY = Math.floor(e.pageY - offset.top);
  28. mouseisup = true;
  29. mouseUp();
  30. }
  31. });
  32. canvas = document.getElementById('canvas');
  33. ctx = canvas.getContext('2d');
  34. })
  35.  
  36. function clearScreen() {
  37. ctx.clearRect(0, 0, canvas.width, canvas.height);
  38. }
  39.  
  40. function drawRect(color, a, b, c, d) {
  41. ctx.strokeStyle = color;
  42. ctx.strokeRect(a, b, c, d);
  43. }
  44.  
  45. function fillRect(color, a, b, c, d) {
  46. ctx.fillStyle = color;
  47. ctx.fillRect(a, b, c, d);
  48. }
  49.  
  50. function drawImage(image, x, y, w, h) {
  51. ctx.drawImage(image, x, y, w, h);
  52. }
  53.  
  54. function drawCircle(color, x, y, r) {
  55. ctx.beginPath();
  56. ctx.arc(x, y, r, 0, 2 * Math.PI, false);
  57. ctx.strokeStyle = color;
  58. ctx.stroke();
  59. }
  60.  
  61. function fillCircle(color, x, y, r) {
  62. ctx.beginPath();
  63. ctx.arc(x, y, r, 0, 2 * Math.PI, false);
  64. ctx.fillStyle = color;
  65. ctx.fill();
  66. }
  67.  
  68. function drawLine(color, startx, starty, endx, endy) {
  69. ctx.beginPath();
  70. ctx.moveTo(startx, starty);
  71. ctx.lineTo(endx, endy);
  72. ctx.strokeStyle = color;
  73. ctx.closePath();
  74. ctx.stroke();
  75. }
  76.  
  77. function fillText(str, x, y) {
  78. ctx.fillText(str, x, y);
  79. }
  80.  
  81. function random(n) {
  82. return Math.floor(Math.random()*(n+1));
  83. }
  84.  
  85. function randomcolor() {
  86. return "rgba(" + random(255) + "," + random(255) + "," + random(255) + "," + random(100)/100 + ")";
  87. }
  88.  
  89. clearscreen = clearScreen;
  90. drawrect = drawRect;
  91. fillrect = fillRect;
  92. drawimage = drawImage;
  93. drawcircle = drawCircle;
  94. drawline = drawLine;
  95. fillcircle = fillCircle;
  96. filltext = fillText;
  97. mousedown = mouseDown;
  98. randomcolour = randomcolor;
Add Comment
Please, Sign In to add comment