HTML Canvas 曲線
實例
const canvas = document.getElementById("myCanvas"); const ctx = canvas.getContext("2d"); ctx.beginPath(); ctx.arc(100, 50, 50, 0, Math.PI); ctx.stroke();
arc() 方法
圓弧是一部分圓,也是由中心點坐標和半徑定義:

Canvas 繪制圓弧
請使用畫布中的路徑來繪制圓弧:
方法 | 描述 | 繪制 |
---|---|---|
beginPath() | 開始一條路徑。 | 否 |
arc() | 定義曲線。 | 否 |
stroke() | 做圖。 | 是 |
要在畫布上繪制圓形,請使用以下方法:
- beginPath() - 開始路徑
- arc(x,y,r,start,end) - 定義圓
- stroke() - 繪制
arc(x,y,r,start,end) - 創建弧(曲線)。
要創建圓,請將起始角度設置為 0,結束角度設置為 2 * Math.PI。
x 和 y 參數定義圓心的坐標。
r 參數定義圓的半徑。