function initSvgGrid() {
  var grid = document.getElementById('grid');
  if (!grid) throw Error('No grid SVG element found.');
  // <line class="grid" x1="19" y1="20" x2="21" y2="20"/>
  // <line class="grid" x1="20" y1="19" x2="20" y2="21"/>
  var LEN = 2;
  for (var x = 0; x <= WIDTH; x++) {
    var matrixX = x * CELL_SIZE;
    for (var y = 0; y <= HEIGHT; y++) {
      var matrixY = y * CELL_SIZE;
      // Horizontal tick.
      if (y > 0 && y < HEIGHT) {
        var line = document.createElementNS(SVG_NS, 'line');
        line.setAttribute('x1', matrixX - LEN + 0.5);
        line.setAttribute('y1', matrixY + 0.5);
        line.setAttribute('x2', matrixX + LEN + 0.5);
        line.setAttribute('y2', matrixY + 0.5);
        line.setAttribute('class', 'grid');
        grid.appendChild(line);
      }
      // Vertical tick.
      if (x > 0 && x < WIDTH) {
        line = document.createElementNS(SVG_NS, 'line');
        line.setAttribute('x1', matrixX + 0.5);
        line.setAttribute('y1', matrixY - LEN + 0.5);
        line.setAttribute('x2', matrixX + 0.5);
        line.setAttribute('y2', matrixY + LEN + 0.5);
        line.setAttribute('class', 'grid');
        grid.appendChild(line);
      }
    }
  }
  var rect = document.createElementNS(SVG_NS, 'rect');
  rect.setAttribute('x', 0.5);
  rect.setAttribute('y', 0.5);
  rect.setAttribute('width', WIDTH * CELL_SIZE);
  rect.setAttribute('height', HEIGHT * CELL_SIZE);
  rect.setAttribute('class', 'grid');
  grid.appendChild(rect);
}
// Draw the grid markers on the board.
Draw the grid markers on the board.
Draw the grid markers on the board .
function initSvgGrid() {
  var grid = document.getElementById('grid');
  if (!grid) throw Error('No grid SVG element found.');
  var LEN = 2;
  for (var x = 0; x <= WIDTH; x++) {
    var matrixX = x * CELL_SIZE;
    for (var y = 0; y <= HEIGHT; y++) {
      var matrixY = y * CELL_SIZE;
      if (y > 0 && y < HEIGHT) {
        var line = document.createElementNS(SVG_NS, 'line');
        line.setAttribute('x1', matrixX - LEN + 0.5);
        line.setAttribute('y1', matrixY + 0.5);
        line.setAttribute('x2', matrixX + LEN + 0.5);
        line.setAttribute('y2', matrixY + 0.5);
        line.setAttribute('class', 'grid');
        grid.appendChild(line);
      }
      if (x > 0 && x < WIDTH) {
        line = document.createElementNS(SVG_NS, 'line');
        line.setAttribute('x1', matrixX + 0.5);
        line.setAttribute('y1', matrixY - LEN + 0.5);
        line.setAttribute('x2', matrixX + 0.5);
        line.setAttribute('y2', matrixY + LEN + 0.5);
        line.setAttribute('class', 'grid');
        grid.appendChild(line);
      }
    }
  }
  var rect = document.createElementNS(SVG_NS, 'rect');
  rect.setAttribute('x', 0.5);
  rect.setAttribute('y', 0.5);
  rect.setAttribute('width', WIDTH * CELL_SIZE);
  rect.setAttribute('height', HEIGHT * CELL_SIZE);
  rect.setAttribute('class', 'grid');
  grid.appendChild(rect);
}
function initSvgGrid ( ) { var grid = document . getElementById ( 'grid' ) ; if ( ! grid ) throw Error ( 'No grid SVG element found.' ) ; var LEN = 2 ; for ( var x = 0 ; x <= WIDTH ; x ++ ) { var matrixX = x * CELL_SIZE ; for ( var y = 0 ; y <= HEIGHT ; y ++ ) { var matrixY = y * CELL_SIZE ; if ( y > 0 && y < HEIGHT ) { var line = document . createElementNS ( SVG_NS , 'line' ) ; line . setAttribute ( 'x1' , matrixX - LEN + 0.5 ) ; line . setAttribute ( 'y1' , matrixY + 0.5 ) ; line . setAttribute ( 'x2' , matrixX + LEN + 0.5 ) ; line . setAttribute ( 'y2' , matrixY + 0.5 ) ; line . setAttribute ( 'class' , 'grid' ) ; grid . appendChild ( line ) ; } if ( x > 0 && x < WIDTH ) { line = document . createElementNS ( SVG_NS , 'line' ) ; line . setAttribute ( 'x1' , matrixX + 0.5 ) ; line . setAttribute ( 'y1' , matrixY - LEN + 0.5 ) ; line . setAttribute ( 'x2' , matrixX + 0.5 ) ; line . setAttribute ( 'y2' , matrixY + LEN + 0.5 ) ; line . setAttribute ( 'class' , 'grid' ) ; grid . appendChild ( line ) ; } } } var rect = document . createElementNS ( SVG_NS , 'rect' ) ; rect . setAttribute ( 'x' , 0.5 ) ; rect . setAttribute ( 'y' , 0.5 ) ; rect . setAttribute ( 'width' , WIDTH * CELL_SIZE ) ; rect . setAttribute ( 'height' , HEIGHT * CELL_SIZE ) ; rect . setAttribute ( 'class' , 'grid' ) ; grid . appendChild ( rect ) ; }
Draw the grid markers on the board.
Draw the grid markers on the board .
// <line class="grid" x1="19" y1="20" x2="21" y2="20"/> // <line class="grid" x1="20" y1="19" x2="20" y2="21"/> // Horizontal tick. // Vertical tick.