Java 类javafx.scene.paint.LinearGradientBuilder 实例源码

项目:javafx-demos    文件:DisplacementMapBannerDemo.java   
public Banner(String message) {
    Rectangle rectangle = RectangleBuilder
            .create()
            .x(0)
            .y(0)
            .width(W)
            .height(H)
            .fill(LinearGradientBuilder
                    .create()
                    .startX(0.0)
                    .startY(0.0)
                    .endX(10.0)
                    .endY(0.0)
                    .proportional(false)
                    .cycleMethod(CycleMethod.REFLECT)
                    .stops(StopBuilder.create().offset(0.0).color(Color.BLUE).build(),
                            StopBuilder.create().offset(1.0).color(Color.LIGHTBLUE).build()).build()).build();
    Text text = TextBuilder.create().x(25).y(H / 16).text(message).fill(Color.YELLOW).font(Font.font(null, FontWeight.BOLD, 36))
            .build();
    getChildren().addAll(rectangle, text);
}
项目:Fishification    文件:FishEntity.java   
private void createFlagWithRopes() {

        // Fill the flag with yellow gradient
        LinearGradient textRectGradient = LinearGradientBuilder.create().startX(50).startY(50).endX(100).endY(
                100).proportional(false).stops(new Stop(0.0f, Color.rgb(220, 220, 220, .784)),
                                               new Stop(1.0f, Color.rgb(180, 180, 180, .784))).build();
        m_flagRect.setFill(textRectGradient);

        // Adjust the flags position
        Bounds textBounds = m_flagText.getBoundsInLocal();
        double baseLineOffset = m_flagText.getBaselineOffset();
        m_flagRect.setTranslateX(m_flagText.getTranslateX() - FLAG_PADDING);
        m_flagRect.setTranslateY(m_flagText.getTranslateY() - baseLineOffset - FLAG_PADDING);
        m_flagRect.setWidth(textBounds.getWidth() + FLAG_PADDING * 2);
        m_flagRect.setHeight(textBounds.getHeight() + FLAG_PADDING * 2);

        // Create flag rope #01
        MoveTo moveTo1 = new MoveTo(m_fishSprite.getWidth() / 2, m_fishSprite.getHeight() / 2);
        LineTo lineTo1 = new LineTo(m_flagRect.getTranslateX() + m_flagRect.getWidth(), m_flagRect.getTranslateY());
        if (s_directionInvertedX) {
            lineTo1.setX(m_flagRect.getTranslateX());
        }
        m_flagRope1.getElements().add(moveTo1);
        m_flagRope1.getElements().add(lineTo1);
        m_flagRope1.setStrokeWidth(FLAG_ROPE_STROKE_WIDTH);
        m_flagRope1.setStroke(Color.rgb(0, 0, 0, 0.5));

        // Create flag rope #02
        MoveTo moveTo2 = new MoveTo(m_fishSprite.getWidth() / 2, m_fishSprite.getHeight() / 2);
        LineTo lineTo2 = new LineTo(m_flagRect.getTranslateX() + m_flagRect.getWidth(),
                                    m_flagRect.getTranslateY() + m_flagRect.getHeight());
        if (s_directionInvertedX) {
            lineTo2.setX(m_flagRect.getTranslateX());
        }
        m_flagRope2.getElements().add(moveTo2);
        m_flagRope2.getElements().add(lineTo2);
        m_flagRope2.setStrokeWidth(FLAG_ROPE_STROKE_WIDTH);
        m_flagRope2.setStroke(Color.rgb(0, 0, 0, 0.5));
    }