所以我正在嘗試使用 arc 函式繪制一個多邊形。我知道有更好的方法來繪制多邊形,但稍后我將使用這個功能來繪制點。
我的形狀繪制沒有問題,但是,弧形路徑是可見的,所以我想知道是否只有一種簡單的方法可以將其從路徑中洗掉。我已經嘗試了幾件事,但我沒有在網上找到任何東西。
如果做不到這一點,是否有辦法在繪制圓弧之前存盤當前位置并使用該位置從端點創建線?
start = 0;
inc = 360 / sides;
con.strokeStyle = 'rgb(73, 150, 210)';
con.lineWidth = 8;
for(i = 1; i <= sides; i ){
end = inc * i;
con.beginPath();
con.arc(500, 500, 500, toRadians(start), toRadians(end));
con.closePath();
con.stroke();
start = end;
}

編輯:有人推薦了另一篇關于透明度的帖子,我在那篇帖子中沒有看到任何關于將 closePath 與實際路徑本身分開的內容。也許我錯過了一些東西,因為那篇文章相當長。
uj5u.com熱心網友回復:
這種修改后的方法怎么樣?
const con = canvas.getContext("2d");
const sides = 10;
con.strokeStyle = 'rgb(73, 150, 210)';
con.lineWidth = 1;
con.beginPath();
// for loop from i=0 to i = sides 1
// j is the angle we are currently at
// use sin & cos aggregate methods to get the positions on 2d grid
for (let i = 0, j=2 * Math.PI / sides; i <= sides 1; i , j = i * 2 * Math.PI / sides)
con.lineTo(50 50 * Math.cos(j), 50 50 * Math.sin(j));
con.stroke();
<canvas id="canvas" width="100px" height="100px"></canvas>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/448701.html
標籤:javascript php html 帆布
