My simple code is intended to draw a circle, but it's not appearing as expected. The coordinates seem to be shifted oddly. The canvas size is specified with
style="width: 600px; height: 600px;"
. I've tested it on both Chrome and Safari, yet the results are the same so it doesn't appear to be a browser issue.
So here are my questions (which likely have the same answer):
- If I place the center at (100, 100), why isn't the circle equidistant from the left and top borders?
- Why does the point (300, 300) fall outside the canvas instead of being in the center?
Here's the code snippet:
var context = document.getElementById('c').getContext("2d");
context.fillStyle = 'black';
context.fill();
context.beginPath();
context.arc(100, 100, 30, 0, 2 * Math.PI, true);
context.stroke();
Current rendering:
Edit
After discovering a comment, I realized that using
<canvas id="myCanvas" style="width: 578px; height: 200px;"></canvas>
was causing the problem, whereas changing it to <canvas id="myCanvas" width="578" height="200"></canvas>
solved the issue. Does anyone know why this is the case?