コード例 #1
0
ファイル: Main.java プロジェクト: tommykw/JavaFXSandbox
  @Override
  public void start(Stage primaryStage) throws Exception {
    Group root = new Group();
    Group circles = new Group();
    for (int i = 0; i < 30; i++) {
      Circle circle = new Circle(150, Color.web("white", 0.05));
      circle.setStrokeType(StrokeType.OUTSIDE);
      circle.setStroke(Color.web("white", 0.16));
      circle.setStrokeWidth(4);
      circles.getChildren().add(circle);
    }
    root.getChildren().add(circles);
    Scene scene = new Scene(root, 800, 600, Color.BLACK);
    Rectangle colors =
        new Rectangle(
            scene.getWidth(),
            scene.getHeight(),
            new LinearGradient(
                0f,
                1f,
                1f,
                0f,
                true,
                CycleMethod.NO_CYCLE,
                new Stop[] {
                  new Stop(0, Color.web("#f8bd55")),
                  new Stop(0.14, Color.web("#c0fe56")),
                  new Stop(0.28, Color.web("#5dfbc1")),
                  new Stop(0.43, Color.web("#64c2f8")),
                  new Stop(0.57, Color.web("#be4af7")),
                  new Stop(0.71, Color.web("#ed5fc2")),
                  new Stop(0.85, Color.web("#ef504c")),
                  new Stop(1, Color.web("#f2660f")),
                }));
    colors.widthProperty().bind(scene.widthProperty());
    colors.heightProperty().bind(scene.heightProperty());
    root.getChildren().add(colors);

    Timeline timeline = new Timeline();
    for (Node circle : circles.getChildren()) {
      timeline
          .getKeyFrames()
          .addAll(
              new KeyFrame(
                  Duration.ZERO, // set start position at 0
                  new KeyValue(circle.translateXProperty(), random() * 800),
                  new KeyValue(circle.translateYProperty(), random() * 600)),
              new KeyFrame(
                  new Duration(40000), // set end position at 40s
                  new KeyValue(circle.translateXProperty(), random() * 800),
                  new KeyValue(circle.translateYProperty(), random() * 600)));
    }
    timeline.play();
    primaryStage.setScene(scene);
    primaryStage.show();
  }
コード例 #2
0
 /**
  * Create new QuickShakeTransition
  *
  * @param node The node to affect
  */
 public PanicShakeTransition(final Node node) {
   super(
       node,
       new Timeline(
           new KeyFrame(Duration.millis(0), new KeyValue(node.translateXProperty(), 0, WEB_EASE)),
           new KeyFrame(
               Duration.millis(DURATION * .08),
               new KeyValue(node.translateXProperty(), -10, WEB_EASE)),
           new KeyFrame(
               Duration.millis(DURATION * .25),
               new KeyValue(node.translateXProperty(), 10, WEB_EASE)),
           new KeyFrame(
               Duration.millis(DURATION * .41),
               new KeyValue(node.translateXProperty(), -10, WEB_EASE)),
           new KeyFrame(
               Duration.millis(DURATION * .58),
               new KeyValue(node.translateXProperty(), 10, WEB_EASE)),
           new KeyFrame(
               Duration.millis(DURATION * .75),
               new KeyValue(node.translateXProperty(), -5, WEB_EASE)),
           new KeyFrame(
               Duration.millis(DURATION * .92),
               new KeyValue(node.translateXProperty(), 5, WEB_EASE)),
           new KeyFrame(
               Duration.millis(DURATION * 1.00),
               new KeyValue(node.translateXProperty(), 0, WEB_EASE))));
   setCycleDuration(Duration.millis(DURATION));
   setInterpolator(Interpolator.EASE_BOTH);
   setDelay(Duration.seconds(0.2));
 }
コード例 #3
0
 /**
  * Create new FadeInUpTransition
  *
  * @param node The node to affect
  */
 public FadeInRightTransition(final Node node) {
   super(
       node,
       TimelineBuilder.create()
           .keyFrames(
               new KeyFrame(
                   Duration.millis(0),
                   new KeyValue(node.opacityProperty(), 0, WEB_EASE),
                   new KeyValue(node.translateXProperty(), 20, WEB_EASE)),
               new KeyFrame(
                   Duration.millis(1000),
                   new KeyValue(node.opacityProperty(), 1, WEB_EASE),
                   new KeyValue(node.translateXProperty(), 0, WEB_EASE)))
           .build());
   setCycleDuration(Duration.seconds(1));
   setDelay(Duration.seconds(0.2));
 }
コード例 #4
0
  public void registerLayer(Class<? extends Layer> clazz, Layer layer, Node layerNode) {
    layers.put(clazz, layer);

    if (layerNode != null) {
      pane.getChildren().add(layerNode);
      layerNode.toFront();

      hvalueProperty()
          .addListener(
              (ov, n, o) ->
                  layerNode
                      .translateXProperty()
                      .set(o.doubleValue() * (pane.getWidth() - getViewportBounds().getWidth())));
      vvalueProperty()
          .addListener(
              (ov, n, o) ->
                  layerNode
                      .translateYProperty()
                      .set(o.doubleValue() * (pane.getHeight() - getViewportBounds().getHeight())));
    }
  }
コード例 #5
0
  private void addAnimation(
      ArrayList<KeyFrame> keyFrames, final AnimationPartBase annimation, long minTime) {
    long startTimeMs = annimation.startTime - minTime;
    long endTimeMs = annimation.endTime - minTime;

    final Node node = annimation.createVisualRepresentation();

    KeyValue keyValueStartX = new KeyValue(node.translateXProperty(), annimation.startx);
    KeyValue keyValueStartY = new KeyValue(node.translateYProperty(), annimation.starty);
    KeyValue keyValueEndX =
        new KeyValue(node.translateXProperty(), annimation.endx, Interpolator.EASE_BOTH);
    KeyValue keyValueEndY =
        new KeyValue(node.translateYProperty(), annimation.endy, Interpolator.EASE_BOTH);

    KeyFrame keyFrame1 =
        new KeyFrame(
            Duration.millis(startTimeMs),
            new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent event) {
                animationPane.getChildren().add(node);
              }
            },
            new KeyValue(node.opacityProperty(), 0));
    KeyFrame keyFrame2 = new KeyFrame(Duration.millis(startTimeMs), keyValueStartX, keyValueStartY);
    KeyFrame keyFrame3 =
        new KeyFrame(
            Duration.millis(startTimeMs + FADEDURATION), new KeyValue(node.opacityProperty(), 1));
    KeyFrame keyFrame4 =
        new KeyFrame(Duration.millis(startTimeMs + FADEDURATION), keyValueStartX, keyValueStartY);
    KeyFrame keyFrame5 =
        new KeyFrame(Duration.millis(endTimeMs - FADEDURATION), keyValueEndX, keyValueEndY);
    KeyFrame keyFrame6 =
        new KeyFrame(
            Duration.millis(endTimeMs - FADEDURATION), new KeyValue(node.opacityProperty(), 1));
    KeyFrame keyFrame7 =
        new KeyFrame(
            Duration.millis(endTimeMs),
            new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent event) {
                animationPane.getChildren().remove(node);
              }
            },
            new KeyValue(node.opacityProperty(), 0));

    keyFrames.add(keyFrame1);
    keyFrames.add(keyFrame2);
    keyFrames.add(keyFrame3);
    keyFrames.add(keyFrame4);
    keyFrames.add(keyFrame5);
    keyFrames.add(keyFrame6);
    keyFrames.add(keyFrame7);

    timeline
        .statusProperty()
        .addListener(
            new ChangeListener<Status>() {
              @Override
              public void changed(
                  ObservableValue<? extends Status> observable, Status oldValue, Status newValue) {
                if (newValue == Status.STOPPED) { // clean up when animation stopped
                  animationPane.getChildren().remove(node);
                }
              }
            });
  }
コード例 #6
0
ファイル: ColorfulCircles.java プロジェクト: andresmr/JavaFx
  @Override
  public void start(Stage primaryStage) {

    /*
     * Es recomendable usar un grupo de nodos como raiz de la escena.
     * El tamaño del grupo depende del tamaño de los nodos.
     */
    Group root = new Group();
    // Pinto una escena negra de 800 * 600
    Scene scene = new Scene(root, 800, 600, Color.BLACK);
    primaryStage.setScene(scene);

    // A continuacion vamos a pintar 30 circulos
    Group circles = new Group();

    for (int i = 0; i < 30; i++) {

      // Creo un criculo con un radio de 150, color blanco y opacidad del 5%
      Circle circle = new Circle(150, Color.web("white", 0.05));

      // Creo un borde alrededor del circulo
      circle.setStrokeType(StrokeType.OUTSIDE);

      // Color del borde del circulo y opacidad
      circle.setStroke(Color.web("white", 0.16));

      // ancho del borde exterior del circulo
      circle.setStrokeWidth(4);

      // Añado el grupo de circulos a la raiz (root)
      circles.getChildren().add(circle);
    }

    Rectangle colors =
        new Rectangle(
            scene.getWidth(),
            scene.getHeight(),
            new LinearGradient(
                0f,
                1f,
                1f,
                0f,
                true,
                CycleMethod.NO_CYCLE,
                new Stop[] {
                  new Stop(0, Color.web("#f8bd55")),
                  new Stop(0.14, Color.web("#c0fe56")),
                  new Stop(0.28, Color.web("#5dfbc1")),
                  new Stop(0.43, Color.web("#64c2f8")),
                  new Stop(0.57, Color.web("#be4af7")),
                  new Stop(0.71, Color.web("#ed5fc2")),
                  new Stop(0.85, Color.web("#ef504c")),
                  new Stop(1, Color.web("#f2660f")),
                }));

    colors.widthProperty().bind(scene.widthProperty());

    colors.heightProperty().bind(scene.heightProperty());

    Group blendModeGroup =
        new Group(
            new Group(new Rectangle(scene.getWidth(), scene.getHeight(), Color.BLACK), circles),
            colors);

    colors.setBlendMode(BlendMode.OVERLAY);

    root.getChildren().add(blendModeGroup);

    // Añadimos un efecto de desenfocado a los circulos
    circles.setEffect(new BoxBlur(10, 10, 3));

    Timeline timeline = new Timeline();
    for (Node circle : circles.getChildren()) {
      timeline
          .getKeyFrames()
          .addAll(
              new KeyFrame(
                  Duration.ZERO, // set start position at 0
                  new KeyValue(circle.translateXProperty(), random() * 800),
                  new KeyValue(circle.translateYProperty(), random() * 600)),
              new KeyFrame(
                  new Duration(40000), // set end position at 40s
                  new KeyValue(circle.translateXProperty(), random() * 800),
                  new KeyValue(circle.translateYProperty(), random() * 600)));
    }

    timeline.play();

    primaryStage.show();
  }