Richard's answer seems very plausible, unfortunately, this did not work for me (the gradient did not rotate with the line).
So, I looked for the length and width of the earth, looking for a line for plotting a function from point A to B with a gradient. One person helped me, and now I can share with you respected Syrian knights the answer to all questions:
// I eliminated most of the variables in order to optimize it // mtx is matrix, gfx is Graphics public function LineGradient( pt1 : FlxPoint, pt2 : FlxPoint ) : void { var ox : Number = Math.min( pt1.x, pt2.x); var oy : Number = Math.min( pt1.y, pt2.y); mtx.createGradientBox(Math.abs( pt2.x - pt1.x ), Math.abs( pt2.y - pt1.y ), Math.atan2( pt2.y - pt1.y, pt2.x - pt1.x ), ox, oy ); gfx.lineStyle( thickness, color, alpha); gfx.lineGradientStyle(GradientType.LINEAR, [0xff0000, 0x0000ff], [0, 1], [0, 255], mtx); gfx.moveTo( pt1.x, pt1.y ); gfx.lineTo( pt2.x, pt2.y ); }
Flash will not die now.
source share