4
我正在使用點數組繪製綠線。
for(var i = this.trail.length - 1; i > -1 + 1; i--)
{
var time = this.trail[i][0];
var pos = this.trail[i][1];
var pos2 = this.trail[i - 1][1];
var difference = currentTime - time;
var alpha = ((falloffTime - difference)/255.0)/255.0;
if(alpha < 0)
alpha = 0;
pos = camera.WorldToScreen(pos.x, pos.y);
pos2 = camera.WorldToScreen(pos2.x, pos2.y);
con.moveTo(pos.x, pos.y);
con.lineTo(pos2.x, pos2.y);
con.lineWidth = 3;
con.strokeStyle = "rgba(128, 190, 3, " + alpha + ")";
con.stroke();
}
目前我正在繪製一個循環,以便我可以設置阿爾法。
但是,繪製的線看起來有點鋸齒狀。
我知道,如果我畫它作爲一個單一的線,我可以用
con.lineJoin="round";
爲了使邊緣光滑。 問題是如果我把它全部畫成一行。我不能有一半淡出。 因爲如果我使用漸變,它將只應用於繪製的第一條單線而不是整條線。
所以我的問題是。我如何繪製一條邊緣平滑的線條,並使其淡出?
http://stackoverflow.com/questions/7054272/how-to-draw-smooth-curve-through-n-points-using-javascript-html5-canvas –
可能的重複[如何通過N繪製平滑曲線點使用JavaScript的HTML5畫布?](http://stackoverflow.com/questions/7054272/how-to-draw-smooth-curve-through-n-points-using-javascript-html5-canvas) – Kaiido
第二個答案會給一個點數組,這將允許您停止並重新啓動繪圖(並因此像您一樣改變顏色)。但請注意,在給定的代碼塊中,您並未調用beginPath,因此在循環中您一遍又一遍地繪製相同的路徑塊。 – Kaiido