I am drawing a green line using an array of points.
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();
}
Currently I am drawing it in a loop so that I can set the alpha.
However, the line that is drawn looks a bit jagged.
I know that if I draw it all as a single line, I can use
con.lineJoin="round";
To make the edges smooth. The issue is that if I draw it all as a single line. I can't have half fade out. Since if I use a gradient, it will only apply to the first single line drawn and not the entire trail.
So my question is. How can I draw a line that has smooth edges and I can make it fade out?