JavaFx neon sign

During the weekend i decided to work on neon sign with Glow effect,Reflection and StrokeTransition
here is the code:

    @Override
    public void start(Stage primaryStage)   {

    StackPane root=new StackPane();
   

    Text text=new Text("JAVAFX NEON");
    text.setFill(Color.TRANSPARENT);
    text.setStrokeWidth(3);
    text.setFont(Font.font("arial",100));

   
    Rectangle rect=new Rectangle();
    rect.setWidth(text.getBoundsInParent().getWidth()+15);
    rect.setHeight(text.getBoundsInParent().getHeight()*2);
    rect.setArcHeight(5);
    rect.setArcWidth(5);
    rect.setFill(Color.TRANSPARENT);
    rect.setStroke(Color.RED);
    rect.setStrokeWidth(5);
    rect.setBlendMode(BlendMode.ADD);
   
    StrokeTransition rect_stroke_trans = new StrokeTransition(Duration.millis(70),rect,Color.RED,         Color.GREENYELLOW);
    rect_stroke_trans.setDelay(Duration.millis(200));
    rect_stroke_trans.setCycleCount(Timeline.INDEFINITE);
    rect_stroke_trans.setAutoReverse(true);
    rect_stroke_trans.play();

    Glow glow=new Glow();
    glow.setLevel(0.7);
   
    Reflection ref=new Reflection();
    ref.setFraction(0.5);
    ref.setInput(glow);
   
    text.setEffect(ref);
    rect.setEffect(ref);
   
    StrokeTransition text_stroke_trans = new StrokeTransition(Duration.millis(300),text, Color.RED,        Color.GREENYELLOW);
    text_stroke_trans.setDelay(Duration.millis(200));
    text_stroke_trans.setCycleCount(Timeline.INDEFINITE);
    text_stroke_trans.setAutoReverse(true);
    text_stroke_trans.play();

   root.getChildren().addAll(rect,text);
   Scene scene = new Scene(root,700, 250);
   scene.getStylesheets().add(this.getClass().getResource("style.css").toExternalForm());
   primaryStage.setTitle("JavaFx Neon Sign");
   primaryStage.setScene(scene);
   primaryStage.show();

RESULTS


NB/The background image is inside the css file located at the same folder as the source file

Comments

Popular Posts