PHP前端开发

如何在HTML5画布中绘制椭圆?

百变鹏仔 4周前 (09-22) #HTML
文章标签 画布

您可以尝试运行以下代码在 html5 画布中绘制椭圆形 -

示例

<!DOCTYPE HTML><html>   <head>   </head>   <body>      <canvas id="newCanvas" width="450" height="300"></canvas>      <script>         // canvas         var c = document.getElementById(&#39;newCanvas&#39;);         var context = c.getContext(&#39;2d&#39;);         var cX = 0;         var cY = 0;         var radius = 40;                  context.save();         context.translate(c.width / 2, c.height / 2);         context.scale(2, 1);         context.beginPath();         context.arc(cX, cY, radius, 0, 2 * Math.PI, false);         context.restore();         context.fillStyle = &#39;#000000&#39;;         context.fill();         context.lineWidth = 2;         context.strokeStyle = &#39;yellow&#39;;         context.stroke();      </script>   </body></html>

输出