If I use a gradient on a Line2D, which...
- has interpolation_mode set to GRADIENT_INTERPOLATE_CONSTANT
- consists of more than 2 points
...the gradient moves more to the end instead of being in the middle.
This happens only with interpolation_mode GRADIENT_INTERPOLATE_CONSTANT, but not with the other 2 modes.
Example:
This is how it looks like with GRADIENT_INTERPOLATE_CONSTANT:

This is my code:
# setup gradient
var g = Gradient.new()
g.set_color( 0, Color.red )
g.set_color( 1, Color.green )
#g.interpolation_mode = Gradient.GRADIENT_INTERPOLATE_LINEAR # 0
g.interpolation_mode = Gradient.GRADIENT_INTERPOLATE_CONSTANT # 1
#g.interpolation_mode = Gradient.GRADIENT_INTERPOLATE_CUBIC # 2
# draw line with gradient
var line = Line2D.new()
line.width = 100
line.antialiased = true
line.set_begin_cap_mode( Line2D.LINE_CAP_ROUND )
line.set_end_cap_mode( Line2D.LINE_CAP_ROUND)
var points = PoolVector2Array()
points.append( Vector2( 100 + 0*200, 200 ) )
points.append( Vector2( 100 + 2*200, 200 ) )
points.append( Vector2( 100 + 4*200, 200 ) )
for p in points:
line.add_point(p)
line.set_gradient( g )
self.add_child(line)
If I set
g.interpolation_mode = Gradient.GRADIENT_INTERPOLATE_LINEAR
or if I comment the 2nd point of the line (#points.append( Vector2( 100 + 2*200, 200 ) )
), then it looks as expected:

How can I make the gradient spread evenly for a Line2D with any number of points and independant from interpolation mode?