Browser can't render the circle

Jami

I have this script and markup.

<canvas id="myCanvas" style="width:100px; height:100px; background-color:aqua" > 
</canvas>
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var centerX = canvas.width / 2;
var centerY = canvas.height / 2;
var radius = 10;

context.beginPath();
context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
context.fillStyle = 'green';
context.fill();
context.lineWidth = 5;
context.strokeStyle = '#003300';
context.stroke();
</script>

The problem is , the browser depicts an eclipse instead of circle. why is it?

apsillers

You have distorted your canvas by changing its size with CSS styles. Instead, set its size using the height and width properties directly on the tag:

<canvas id="myCanvas" width="100" height="100" style="background-color:aqua">

The circle-to-elipse distortion arises because canvas are by default wider than they are tall, but you have used CSS to force the browser to render a wide rectangle of canvas pixels as a square. By using height and width properties, you change the number of pixels in the canvas, instead of changing the size they occupy.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Bootstrap in Wordpress theme doesn't render in browser

From Dev

NavigationExperimental Can't render overlay

From Dev

Can't render primefaces components?

From Dev

Can't render date in template

From Dev

Can't get sprite to move in a circle path

From Dev

I can't draw a circle in swing

From Dev

Can't get a SVG circle animated

From Dev

Can't fill circle background with color threshold

From Dev

Can't resolve mLatLng in Center of the circle

From Dev

Can't download Chromium browser

From Dev

Can't play video in browser

From Dev

Can't download Chromium browser

From Dev

Can render javascript from controller but can't render .js file

From Dev

Can I force the browser to render DOM changes during javascript execution

From Java

Can I render warning message if user's browser is not supported?

From Dev

How can we render mathjax equation in web browser control?

From Dev

Why doesn't the browser render a response from the controller?

From Dev

Refreshing page after making changes doesn't render in web browser

From Dev

Why can't I render this angularJS code?

From Dev

Can't Get Divs to render Side By Side

From Dev

Can't render some variables in twig template

From Dev

Can't get page to render. Django

From Dev

GSON can't render my HTTPServletRequest parameters

From Dev

Can't add render callback to output unit

From Dev

Can't render triangle in OpenGL C++

From Dev

Can't use PhantomJS render options in Poltergeist

From Dev

Can`t render django form in the template

From Dev

Can't Get Spinning Cube To Render In OpenGL

From Dev

Can't Get Spinning Cube To Render In OpenGL