I have a very simple code that should draw a circle, but its not looking like one, and not at the right position The coordinates are all somewhat shifted. The canvas is set to style="width: 600px; height: 600px;"
. I tried it on chrome and safari - looks the same so it's not a browser bug.
So my questions are (there is probably one answer for both):
- If I am putting the center at (100, 100), why is the circle not at an equal distance from the left border, that it is from the top border?
- Why is the (300, 300) point out of the canvas, and not in the center?
The code:
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();
How it looks:
Edit
According to the comment I found out that writing <canvas id="myCanvas" style="width: 578px; height: 200px;"></canvas>
is causing this problem, and writing <canvas id="myCanvas" width="578" height="200"></canvas>
solves it. Anyone knows why?