欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript canvas繪制圓弧與圓形

 更新時(shí)間:2020年02月18日 07:49:34   作者:IMUDGES_Talon  
這篇文章主要為大家詳細(xì)介紹了JavaScript canvas繪制圓弧與圓形,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了canvas繪制圓弧與圓形的具體代碼,供大家參考,具體內(nèi)容如下

canvas 繪制圓弧

繪制圓弧使用 context.arc( ) 函數(shù),包含六個(gè)參數(shù)。

context.arc(
 centerx,centery,radius,
 startingAngle,endingAngle,
 anticlockwise = false
)

分別代表:圓心 x 值,圓心 y 值,半徑,開(kāi)始的弧度值,結(jié)束的弧度值,(是否逆時(shí)針)。

例如:

window: onload = function(){
 var canvas = document.getElementById("canvas");
 var context = canvas.getContext("2d");
 canvas.width = 800;
 canvas.height = 800;

 context.lineWidth = 5;
 context.strokeStyle = "#005588";
 context.arc(300, 300, 200, 0, 1.5*Math.PI)
 context.stroke();
}

當(dāng)需要繪制多條圓弧時(shí),還是需要調(diào)用 context.beginPath( ) 和 context.closePath( ) 。但是當(dāng)使用 context.closePath( ) 時(shí),會(huì)自動(dòng)將圖形封閉,因此如果需要繪制不封閉圓弧,可以省略 context.closePath( )。

繪制實(shí)心圓

跟之前的多邊形一樣,使用 context.fill( ) ,代碼:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <title>Document</title>
</head>
<body>
 <canvas id="canvas"></canvas>
 <script>
  window: onload = function(){
   var canvas = document.getElementById("canvas");
   var context = canvas.getContext("2d");
   canvas.width = 800;
   canvas.height = 800;

   context.lineWidth = 5;
   context.strokeStyle = "#005588";
   context.arc(300, 300, 200, 0, 1.5*Math.PI)
   context.stroke();
   context.fillStyle = "red";
   context.fill();
  }
 </script>
</body>
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論