上QQ阅读APP看书,第一时间看更新
Gradients
Gradients are complex color sequences which change linearly from one to another.
In JavaFX API, each color break is defined by the Stop class. Also, by setting coordinates, you can adjust the gradient's direction. For example, in the following code the gradient goes from black to white and from the top-left corner to the bottom-right one:
// chapter2/paint/GradientDemo.java
Rectangle rect = new Rectangle(300, 200);
Stop[] stops = new Stop[]{
new Stop(0, Color.BLACK),
new Stop(1, Color.ANTIQUEWHITE)};
LinearGradient lg1 = new LinearGradient(0, 0, 300, 200, false, CycleMethod.NO_CYCLE, stops);
rect.setFill(lg1);