Example #1
0
  @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();
  }
 /**
  * Create new FadeInUpTransition
  *
  * @param node The node to affect
  */
 public FadeInUpTransition(final Node node) {
   super(
       node,
       TimelineBuilder.create()
           .keyFrames(
               new KeyFrame(
                   Duration.millis(0),
                   new KeyValue(node.opacityProperty(), 0, WEB_EASE),
                   new KeyValue(node.translateYProperty(), 20, WEB_EASE)),
               new KeyFrame(
                   Duration.millis(500),
                   new KeyValue(node.opacityProperty(), 1, WEB_EASE),
                   new KeyValue(node.translateYProperty(), 0, WEB_EASE)))
           .build());
   setCycleDuration(Duration.seconds(1));
   setDelay(Duration.seconds(0));
   node.toFront();
 }
  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())));
    }
  }
  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);
                }
              }
            });
  }
Example #5
0
  @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();
  }