chessboard canvas , loop and get some checkers as a circles in JS canvas

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


chessboard canvas , loop and get some checkers as a circles in JS canvas



I am struggling how to create multiple checkers on the checkerboard
I have this JS code so far:


<script>
$(document).ready(function() {
var gColor = "black";
var c = $("#myCanvas")[0];
var ctx = c.getContext("2d");

ctx.lineWidth = 2;
ctx.strokeStyle = "black"; //set the color, gradient, or pattern for stroke

drawBoard();
$("#color").click(function () {
gColor = $("#color").val();
if (gColor > "")
drawBoard();
});

function drawBoard() {
var x, y, step = 60, step2 = 120;
ctx.rect(0,0,480,480);
ctx.stroke();
ctx.save();

for (var k=0; k<2; k++) {
step2 -= step;
ctx.translate(0, step*k);
console.log("translate:("+0+","+step*k+")");
for (var y=0; y<4; y++) {
for (var i=0; i<4; i++) {
x = i * 2 * step + step2;
ctx.fillStyle = gColor;
ctx.fillRect(x,y*step*2,step,step);
console.log("fillRect: "+x+","+y*step*2+","+step+","+step+","+gColor);
}
}
}
ctx.restore();
}

var c = $("#myCanvas")[0];
var ctx = c.getContext("2d");

var rad = 90;
for (var i=0; i<1; i++) {
switch (i) {
case 0: ctx.fillStyle = "red";
break;
}
ctx.beginPath();

// Draw circle (x, y, radius, starting angle, ending angle in radian)
ctx.arc(30, 30, 30, 0, 2 * Math.PI);
ctx.fill();
ctx.stroke();

}

});

</script>



I have this output :
enter image description here



But need something like this:
enter image description here



I understand that I need to do some sort of looping, but because I am just learning canvas I don't know where to start. Any help or advice appreciated









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

3NgidosKNqo5N8Kvy3UZaxbNZuKc2egi3YaI6sO3p8hJdUuwtZ,3oNymB4Y,jw6O9Va6BTYyS ggwN31MDeCI,JjgiLd5550u
5QWpRbz,jAuJjO6u5R,hCe ZXiRYBqPgINU7H1u2pLgTt6FQ5M JF qQYh9ZbL9c 9C96 VZ4jqyPODff

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results