Draw squares
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
<title>Chess</title>
|
<title>Chess</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<canvas id="chessBoard" width="600" height="600"></canvas>
|
||||||
<script src="main.js"></script>
|
<script src="main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1 +1,15 @@
|
|||||||
console.log("Hello World!");
|
var _canvas = document.getElementById("chessBoard");
|
||||||
|
|
||||||
|
function drawChessBoard(canvas) {
|
||||||
|
let ctx = canvas.getContext("2d");
|
||||||
|
let w = canvas.width;
|
||||||
|
let h = canvas.height;
|
||||||
|
ctx.fillStyle = '#c0c0c0';
|
||||||
|
for (let r = 0; r < 8; r++) {
|
||||||
|
for (let c = 0; c < 8; c++) {
|
||||||
|
if ((r + c) % 2) ctx.fillRect(w/8*r, h/8*c, w/8, h/8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drawChessBoard(_canvas);
|
||||||
|
|||||||
Reference in New Issue
Block a user