Skip to content

Instantly share code, notes, and snippets.

@sumedhe
Created December 24, 2018 00:24
Show Gist options
  • Select an option

  • Save sumedhe/05b8fe16dab359819df796d4a426a68d to your computer and use it in GitHub Desktop.

Select an option

Save sumedhe/05b8fe16dab359819df796d4a426a68d to your computer and use it in GitHub Desktop.
(function(){
var canvas = document.getElementById('rectmap');
var recSize = 10;
gap = 1;
boardWidth = 100,
boardHeight = 100;
if (canvas.getContext){
var ctx = canvas.getContext('2d');
drawBoard(ctx, boardWidth, boardHeight, recSize);
}
// Draw board
function drawBoard(canvasContext, width, height, recSize) {
var i, j;
for(i = 0; i < width; ++i) {
for(j = 0; j < height; ++j) {
drawHexagon(
ctx,
i * (recSize + gap),
j * (recSize + gap),
recSize,
"red"
);
}
}
}
// Draw Hexagon
function drawHexagon(canvasContext, x, y, recSize, color) {
canvasContext.fillStyle = color;
canvasContext.fillRect(x, y, recSize, recSize);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment