Fading Sample

 

スクリプト

fadingNode.fx

import javafx.animation.Timeline;
import javafx.animation.transition.FadeTransition;
import javafx.scene.effect.GaussianBlur;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.ClosePath;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.PathElement;
import javafx.stage.Stage;
  
// 星の形を表す PathElement
var starElements: PathElement[] = [
    MoveTo { x: 0       y: -50 },
    LineTo { x: 11.803  y: -11.804 },
    LineTo { x: 50      y: -11.804 },
    LineTo { x: 19.098  y: 11.804 },
    LineTo { x: 30.902  y: 50 },
    LineTo { x: 0       y: 26.394 },
    LineTo { x: -30.902 y: 50 },
    LineTo { x: -19.098 y: 11.804 },
    LineTo { x: -50     y: -11.804 },
    LineTo { x: -11.803 y: -11.804 },
    ClosePath {}
];
  
// 星形 
var star: Node = Path {
    translateX: 100
    translateY: 100
    fill: Color.web("#CCCC00")
    stroke: null
     
    elements: starElements
};
 
// ぼかした星形 
var blurredStar: Node = Path {
    translateX: 100
    translateY: 100
    fill: Color.web("#FFFF00")
    stroke: null
 
    // ぼかしをかける
    effect: GaussianBlur {
        radius: 20
    }
 
    elements: starElements
};
 
var fadeTransition = FadeTransition {
    // フェードの対象となるノード
    node: blurredStar

    // 不透明度を 0.3 から 1.0 まで変化させる
    fromValue: 0.3
    toValue: 1.0

    duration: 0.5s
    repeatCount: Timeline.INDEFINITE
    autoReverse: true
};
fadeTransition.play();
 
Stage {
    title: "Fading Sample"
    scene: Scene {
        width: 200
        height: 200
        fill: LinearGradient {
            startX: 0.0, startY: 0.0, endX: 0.0, endY: 1.0
            proportional: true
            stops: [
                Stop { offset: 0.0 color: Color.web("#000022") },
                Stop { offset: 1.0 color: Color.web("#000066") }
            ]
        }
        content: [blurredStar, star]
    }
}