Canvas and arc drawing doesnt work properly in html and javascript

So I have this Canvas on which I have my circle and when I try to change the x and y of my circle it glitches.It appears like this when I try to move it towards the left by changing the x value to 10 changing the x to any other value makes no change: When I change arc's x value to 10 or below

When I change y to more than 110:

When I change arc's y value to 110 or above

HTML:

<span id="span_canvas">
<canvas id ="MyCanvas" style="padding-left: 1215px;padding-bottom: 415px;margin: 
0px;border:ridge rgb(127, 117, 117);"></canvas>
</span>

Javascript:

function Circle(radius ,fillcolor){
    let canvas=document.getElementById("MyCanvas");
    let ctx= canvas.getContext("2d");
    ctx.beginPath();
    ctx.arc(100, 110, 50, 0, 2 * Math.PI);
    ctx.strokeStyle="#c3c3c3";
    ctx.fillStyle=fillcolor
    ctx.stroke()
    ctx.fill();
    fillcolor=red
}

2 answers

  • answered 2022-05-04 11:21 Itagaki Fumihiko

    Remove padding-left: 1215px;padding-bottom: 415px; and see what is going on. The area where the circle appears to be cut out is padding area. In other words, the position of the circle is outside the content area.

  • answered 2022-05-04 11:22 Dropye

    You need to Include Height an Width Tags to xour canvas

    <canvas id ="canvas" height="200px" style="padding-left: 1215px;padding-bottom: 415px;margin: 
    0px;border:ridge rgb(127, 117, 117);"></canvas>
    

    Then it will work.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum