AllenYuan

index.js grid

Apr 30th, 2020
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function () {
  2.   let PIXELSIZE = 2;
  3.   let REPEATSX = 20;
  4.   let REPEATSY = 15;
  5.   let DIMENSION = 25;
  6.  
  7.   let canvas = id('mycanvas');
  8.   let ctx = canvas.getContext("2d");
  9.   let canvasWidth = DIMENSION * REPEATSX * PIXELSIZE;
  10.   let canvasHeight = DIMENSION * REPEATSY * PIXELSIZE;
  11.   let selectedBox = null;
  12.  
  13.   canvas.width = canvasWidth;
  14.   canvas.height = canvasHeight;
  15.  
  16.   // draw grid
  17.   ctx.strokeStyle = '#cccccc';
  18.   for (let i = 0; i < DIMENSION * REPEATSX; i += DIMENSION) {
  19.     x = i * PIXELSIZE;
  20.     ctx.beginPath();
  21.     ctx.moveTo(x, 0);
  22.     ctx.lineTo(x, canvasHeight);
  23.     ctx.stroke();
  24.  
  25.     y = i * PIXELSIZE;
  26.     ctx.beginPath();
  27.     ctx.moveTo(0, y);
  28.     ctx.lineTo(canvasWidth, y);
  29.     ctx.stroke();
  30.   }
  31.  
  32.   function id(id) {
  33.     return document.getElementById(id);
  34.   }
  35. });
Advertisement
Add Comment
Please, Sign In to add comment