import javafx.animation.Animation; import javafx.animation.Interpolator; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.ScaleTransition; import javafx.animation.SequentialTransition; import javafx.animation.Timeline; import javafx.animation.TranslateTransition; import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.shape.Line; import javafx.scene.transform.Scale; import javafx.stage.Stage; import javafx.util.Duration; public class Main extends Application { public static void main(String[] args) { launch(args); } public static final Interpolator EASE_IN_QUART = Interpolator.SPLINE(0.895, 0.03, 0.685, 0.22); public static final Interpolator EASE_OUT_QUART = Interpolator.SPLINE(0.165, 0.84, 0.44, 1); @Override public void start(Stage stage) throws Exception { Pane pane = new Pane(); pane.setStyle("-fx-border-color:white;-fx-border-width:2"); pane.setMaxSize(250, 400); pane.setMinSize(250, 400); Line line = new Line(40, 0, 40, 0); line.setTranslateY(200); line.setStroke(Color.WHITE); line.setStrokeWidth(15); Timeline timeline = new Timeline( new KeyFrame(Duration.ZERO, new KeyValue(line.startXProperty(), 40, Interpolator.DISCRETE)), new KeyFrame(Duration.ZERO, new KeyValue(line.endXProperty(), 40, Interpolator.DISCRETE)), new KeyFrame(Duration.seconds(2), new KeyValue(line.endXProperty(), 210, EASE_OUT_QUART)), new KeyFrame(Duration.seconds(2.5), new KeyValue(line.startXProperty(), 40, EASE_OUT_QUART)), new KeyFrame(Duration.seconds(4), new KeyValue(line.startXProperty(), 210, EASE_OUT_QUART)) ); timeline.setCycleCount(Animation.INDEFINITE); timeline.play(); pane.getChildren().add(line); VBox root = new VBox(pane); root.setAlignment(Pos.CENTER); stage.setScene(new Scene(root, 600, 600, Color.web("#1E1E1E"))); stage.show(); stage.getScene().getAccelerators().put(new KeyCodeCombination(KeyCode.ESCAPE), () -> System.exit(0)); } }
styled using hilite.me
No comments:
Post a Comment