Draw Grid / Table on Canvas HTML5

后端 未结 3 988
死守一世寂寞
死守一世寂寞 2020-12-14 10:59

I\'ve been searching everywhere and couldn\'t find how to draw a Grid / Table on a HTML5 Canvas. I\'m new to HTML5 and canvas.

I know how to draw shapes but this dr

3条回答
  •  -上瘾入骨i
    2020-12-14 11:09

    // Box width
    var bw = 270;
    // Box height
    var bh = 180;
    var canvas = document.getElementById("canvas");
    var context = canvas.getContext("2d");
    function drawBoard(){
        context.lineWidth = 10;
        context.strokeStyle = "rgb(2,7,159)";
        for (var x = 0; x < bw; x += 90) {
            for (var y = 0; y < bh; y += 90) {
               context.strokeRect(x+10, y+10, 90, 90); 
            }
        }
    }
    drawBoard();
    

提交回复
热议问题