The LinearGradient
class fills a shape
with a linear color gradient pattern. The user may specify two or
more gradient colors, and this Paint will provide an interpolation
between each color.
The application provides an array of Stop
s specifying how to distribute
the colors along the gradient. The Stop#offset
variable must be
the range 0.0 to 1.0 and act like keyframes along the gradient.
The offsets mark where the gradient should be exactly a particular color.
If the proportional variable is set to true then the start and end points of the gradient should be specified relative to the unit square (0.0->1.0) and will be stretched across the shape. If the proportional variable is set to false, then the start and end points should be specified in the local coordinate system of the shape and the gradient will not be stretched at all.
The two filled rectangles in the example below will render the same. The one on the left uses proportional coordinates to specify the end points of the gradient. The one on the right uses absolute coordinates. Both of them fill the specified rectangle with a horizontal gradient that varies from black to red
// object bounding box relative (proportional = true) Stop[] stops = new Stop[] { new Stop(0, Color.BLACK), new Stop(1, Color.RED)}; LinearGradient lg1 = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, stops); Rectangle r1 = new Rectangle(0, 0, 100, 100); r1.setFill(lg1); // user space relative (proportional: = false) LinearGradient lg2 = new LinearGradient(125, 0, 225, 0, false, CycleMethod.NO_CYCLE, stops); Rectangle r2 = new Rectangle(125, 0, 100, 100); r2.setFill(lg2);
extends