Skip to content

Instantly share code, notes, and snippets.

@mohsenheydari
Created January 8, 2019 01:31
Show Gist options
  • Save mohsenheydari/56bf9322958f38993ccf5c8b31d0206f to your computer and use it in GitHub Desktop.
Save mohsenheydari/56bf9322958f38993ccf5c8b31d0206f to your computer and use it in GitHub Desktop.
Draw Tic Tac Toe grid lines
drawGrid(){
let offset = 5;
let lineLenght = this.canvas.width - offset;
this.ctx.lineWidth = this.gridLineWidth;
this.ctx.lineCap = 'round';
this.ctx.strokeStyle = this.gridLineStyle;
this.ctx.beginPath();
//Horizontal lines
for (let y = 1;y <= 2;y++) {
this.ctx.moveTo(offset, y * this.cellSize);
this.ctx.lineTo(lineLenght, y * this.cellSize);
}
//Vertical lines
for (let x = 1;x <= 2;x++) {
this.ctx.moveTo(x * this.cellSize, offset);
this.ctx.lineTo(x * this.cellSize, lineLenght);
}
this.ctx.stroke();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment