SOURCE

console 命令行工具 X clear

                    
>
console
 var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

function init (width, height) {
    let interval = 30;
    for(let i =0; i<width/interval; i++) {
            for(let j=1;j<height/interval;j++) {
                let num = 4*j-3;
                console.log(num)
                if (i%2 ===0) {
                    ctx.beginPath();
                    ctx.fillStyle = '#F5270B';
                    ctx.arc((num-1)*interval, 15+i*interval,1,0,Math.PI*2, true);
                    ctx.closePath();
                    ctx.fill(); 

                    ctx.beginPath();
                    ctx.fillStyle = '#F5270B';
                    ctx.arc(num*interval, 15+i*interval,1,0,Math.PI*2, true);
                    ctx.closePath();
                    ctx.fill(); 

                    ctx.beginPath();
                    //设置对象起始点和终点
                    ctx.moveTo((num+1)*interval,15+i*interval);
                    ctx.lineTo((num+2)*interval,15+i*interval);
                    //设置样式
                    ctx.lineWidth = 2;
                    ctx.strokeStyle = "#F5270B";
                    //绘制
                    ctx.stroke();
                } else {
                    ctx.beginPath();
                    ctx.fillStyle = '#F5270B';
                    ctx.arc((num+1)*interval, 15+i*30,1,0,Math.PI*2, true);
                    ctx.closePath();
                    ctx.fill(); 

                    ctx.beginPath();
                    ctx.fillStyle = '#F5270B';
                    ctx.arc((num+2)*interval, 15+i*30,1,0,Math.PI*2, true);
                    ctx.closePath();
                    ctx.fill(); 

                    ctx.beginPath();
                    //设置对象起始点和终点
                    ctx.moveTo((num-1)*interval,15+i*interval);
                    ctx.lineTo(num*interval,15+i*interval);
                    //设置样式
                    ctx.lineWidth = 2;
                    ctx.strokeStyle = "#F5270B";
                    //绘制
                    ctx.stroke();
                }
                
            }
        
        
    }
}
init(300, 300);
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>canvas绘图演示</title>
    <style type="text/css">
        #canvas{
            border: 1px solid #ADACB0;
            display: block;
            margin: 20px auto;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="270" height="300">
        你的浏览器还不支持canvas
    </canvas>
</body>

</html>