Beispiel #1
1
  private void playAudio(Media media) {
    if (mediaView.isVisible() == true) {
      mediaView.setVisible(false);
      display.setVisible(true);
    }
    if (mp != null) {
      mp.dispose();
    }

    mp = new MediaPlayer(media);
    mp.play();

    mp.setAudioSpectrumListener(
        (double timestamp, double duration1, float[] magnitudes, float[] phases) -> {
          display.getChildren().clear();
          int i = 0;
          int x = 10;
          double y = root.getScene().getHeight() / 2;
          Random rand = new Random(System.currentTimeMillis());
          for (float phase : phases) {
            int red = rand.nextInt(255);
            int green = rand.nextInt(255);
            int blue = rand.nextInt(255);
            Circle circle = new Circle(10);
            circle.setCenterX(x + i);
            circle.setCenterY(y + (phase * 100));
            circle.setFill(Color.rgb(red, green, blue, .70));
            display.getChildren().add(circle);
            i += 10;
          }
        });
  }
  @Override
  protected void layoutChildren() {
    super.layoutChildren();

    mainIcon.relocate(getPadding().getLeft(), getPadding().getTop());
    mainIcon.resize(mainIcon.prefWidth(-1), mainIcon.prefHeight(-1));

    double titleX = mainIcon.getLayoutX() + mainIcon.getWidth() + 12;
    double titleY =
        mainIcon.getLayoutY() + (mainIcon.getHeight() - currentTitle.prefHeight(-1)) / 2;
    double titleWidth = getWidth() - titleX * 2;
    double titleHeight = currentTitle.prefHeight(-1);

    currentTitle.relocate(titleX, titleY);
    currentTitle.resize(titleWidth, titleHeight);

    actionBox.relocate(
        getWidth() - getPadding().getRight() - actionBox.prefWidth(-1), getPadding().getTop());
    actionBox.resize(actionBox.prefWidth(-1), actionBox.prefHeight(-1));

    changeViewAnimationTitle.relocate(titleX, titleY);
    changeViewAnimationTitle.resize(titleWidth, titleHeight);

    Insets borderInsets =
        Optional.ofNullable(getBorder()).map(border -> border.getInsets()).orElse(Insets.EMPTY);
    background.setX(borderInsets.getLeft());
    background.setY(borderInsets.getTop());
    background.setWidth(getWidth() - borderInsets.getLeft() - borderInsets.getRight());
    background.setHeight(getHeight() - borderInsets.getTop() - borderInsets.getBottom());

    changeViewAnimationCircle.setCenterX(mainIcon.getLayoutX() + mainIcon.getWidth() / 2);
    changeViewAnimationCircle.setCenterY(mainIcon.getLayoutY() + mainIcon.getHeight() / 2);
  }
Beispiel #3
0
 private void updateCircles() {
   for (int i = 0; i < ballArray.length; i++) {
     Ball b = ballArray[i];
     Circle c = circleArray[i];
     if (b != null) {
       c.setCenterX(b.getXPos());
       c.setCenterY(b.getYPos());
     }
   }
 }
    private void configureBackground() {
      ImageView imageView = new ImageView();
      Image image = loadImage();
      imageView.setImage(image);

      Circle circle1 = new Circle();
      circle1.setCenterX(140);
      circle1.setCenterY(140);
      circle1.setRadius(120);
      circle1.setFill(Color.TRANSPARENT);
      circle1.setStroke(Color.web("#0A0A0A"));
      circle1.setStrokeWidth(0.3);

      Circle circle2 = new Circle();
      circle2.setCenterX(140);
      circle2.setCenterY(140);
      circle2.setRadius(118);
      circle2.setFill(Color.TRANSPARENT);
      circle2.setStroke(Color.web("#0A0A0A"));
      circle2.setStrokeWidth(0.3);

      Circle circle3 = new Circle();
      circle3.setCenterX(140);
      circle3.setCenterY(140);
      circle3.setRadius(140);
      circle3.setFill(Color.TRANSPARENT);
      circle3.setStroke(Color.web("#818a89"));
      circle3.setStrokeWidth(1);

      Ellipse ellipse = new Ellipse(140, 95, 180, 95);
      Circle ellipseClip = new Circle(140, 140, 140);
      ellipse.setFill(Color.web("#535450"));
      ellipse.setStrokeWidth(0);
      GaussianBlur ellipseEffect = new GaussianBlur();
      ellipseEffect.setRadius(10);
      ellipse.setEffect(ellipseEffect);
      ellipse.setOpacity(0.1);
      ellipse.setClip(ellipseClip);
      background.getChildren().addAll(imageView, circle1, circle2, circle3, ellipse);
    }
  /** ********************************************************** */
  public void setObstacles() {
    drawPane.setOnMouseClicked(
        e -> {
          if (Init) {
            object obj = new object(33, 33);
            obj.get().setX(e.getX());
            obj.get().setY(e.getY());
            obj.get().setFill(new Color(0.1, 0.1, 0.7, 0.5));
            obj.setSpeed(3);
            drawPane.getChildren().add(obj);
            Algorithm.add(obj);
          } else {
            TargetPoint.setCenterX(e.getX());
            TargetPoint.setCenterY(e.getY());

            Algorithm.setTarget(e.getX(), e.getY());
          }
        });
  }
  @Override
  public void start(Stage primaryStage) throws Exception {

    Pane pane = new Pane();
    int x = RADIUS + GAP;
    int y = RADIUS + GAP;

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

      // drawing a 2 Circles in each row
      for (int j = 0; j < 2; j++) {
        // create circle
        Circle c = new Circle(RADIUS);
        c.setCenterX(x);
        c.setCenterY(y);
        c.setStroke(Color.BLACK);
        c.setFill(Color.WHITE);
        pane.getChildren().add(c);

        // create 4 arcs in each circle with 90 degree increment
        for (int k = 30; k < 360; k += 90) {
          Arc arc = new Arc(x, y, RADIUS - 15, RADIUS - 15, k, 30);
          arc.setFill(Color.BLACK);
          arc.setType(ArcType.ROUND);
          pane.getChildren().add(arc);
        }

        x += RADIUS * 2 + GAP;
      }
      // reset center for the next row
      x = RADIUS + GAP;
      y += RADIUS * 2 + GAP;
    }

    Scene scene = new Scene(pane, 425, 425);
    primaryStage.setScene(scene);
    primaryStage.setTitle("Fans");
    primaryStage.show();
  }
  // drawing
  public void drawGraph() {

    Timeline timeline = new Timeline();

    if (graph != null && finalCoordinates != null) {

      // reset pane
      drawing.getChildren().clear();
      SpringEmbedder.centerCoordinates(finalCoordinates, 20, 380, 20, 380);
      SpringEmbedder.centerCoordinates(startingCoordinates, 20, 380, 20, 380);

      // draw nucleotides
      circles = new Circle[finalCoordinates.length];
      for (int i = 0; i < finalCoordinates.length; i++) {
        // create nodes
        Circle circle = new Circle(5);
        circle.setCenterX(finalCoordinates[i][0]);
        circle.setCenterY(finalCoordinates[i][1]);
        switch (graph.getSequence().charAt(i)) {
          case 'A':
            circle.setFill(Color.YELLOW);
            break;
          case 'a':
            circle.setFill(Color.YELLOW);
            break;
          case 'U':
            circle.setFill(Color.GREEN);
            break;
          case 'u':
            circle.setFill(Color.GREEN);
            break;
          case 'C':
            circle.setFill(Color.BLUE);
            break;
          case 'c':
            circle.setFill(Color.BLUE);
            break;
          case 'G':
            circle.setFill(Color.RED);
            break;
          case 'g':
            circle.setFill(Color.RED);
            break;
        }
        circle.setStroke(Color.BLACK);
        // add tooltip
        Tooltip t =
            new Tooltip("Nucleotide: " + graph.getSequence().charAt(i) + "\nPosition: " + i);
        Tooltip.install(circle, t);

        // add drag-and-drop behaviour
        circle.setOnMousePressed(
            event -> {
              if (isAnimationActivated) {
                dragStartX = circle.getCenterX();
                dragStartY = circle.getCenterY();
              }
            });

        circle.setOnMouseDragged(
            event -> {
              if (isAnimationActivated) {
                circle.setCenterX(event.getX());
                circle.setCenterY(event.getY());
              }
            });

        circle.setOnMouseReleased(
            event -> {
              if (isAnimationActivated) {
                Timeline dragTimeline = new Timeline();
                KeyValue circlePositionXKey = new KeyValue(circle.centerXProperty(), dragStartX);
                KeyValue circlePositionYKey = new KeyValue(circle.centerYProperty(), dragStartY);
                dragTimeline
                    .getKeyFrames()
                    .add(new KeyFrame(Duration.millis(animationTime), circlePositionXKey));
                dragTimeline
                    .getKeyFrames()
                    .add(new KeyFrame(Duration.millis(animationTime), circlePositionYKey));
                dragTimeline.play();
              }
            });

        // save circle locally
        circles[i] = circle;

        // animate circles
        KeyValue startingXKey = new KeyValue(circle.centerXProperty(), startingCoordinates[i][0]);
        KeyValue finalXKey = new KeyValue(circle.centerXProperty(), circle.getCenterX());
        KeyValue startingYKey = new KeyValue(circle.centerYProperty(), startingCoordinates[i][1]);
        KeyValue finalYKey = new KeyValue(circle.centerYProperty(), circle.getCenterY());
        timeline.getKeyFrames().add(new KeyFrame(Duration.millis(0), startingXKey));
        timeline.getKeyFrames().add(new KeyFrame(Duration.millis(0), startingYKey));
        timeline.getKeyFrames().add(new KeyFrame(Duration.millis(animationTime), finalXKey));
        timeline.getKeyFrames().add(new KeyFrame(Duration.millis(animationTime), finalYKey));
      }

      // create edges
      int[][] edges = graph.getEdges();
      for (int i = 0; i < edges.length; i++) {
        // bind edges to nodes
        Line line =
            new Line(
                finalCoordinates[edges[i][0]][0],
                finalCoordinates[edges[i][0]][1],
                finalCoordinates[edges[i][1]][0],
                finalCoordinates[edges[i][1]][1]);
        line.startYProperty().bind(circles[edges[i][0]].centerYProperty());
        line.startXProperty().bind(circles[edges[i][0]].centerXProperty());
        line.endYProperty().bind(circles[edges[i][1]].centerYProperty());
        line.endXProperty().bind(circles[edges[i][1]].centerXProperty());

        // draw edges
        if (edges[i][1] - edges[i][0] != 1) {
          line.setStroke(Color.CADETBLUE);
        } else {
          line.setFill(Color.DARKGRAY);
        }
        drawing.getChildren().add(line);
      }

      // draw all circles in order to overlap the edges
      drawing.getChildren().addAll(circles);

      if (isAnimationActivated) {
        timeline.play();
      }

    } else {
      throw new IllegalArgumentException(
          "graph is null: "
              + graph.equals(null)
              + "\ncoordinates is null: "
              + finalCoordinates.equals(null));
    }
  }
Beispiel #8
0
  @Override
  public void start(Stage stage) {
    sun.setFitHeight(100);
    sun.setFitWidth(100);
    sun.setX(200);
    sun.setY(200);
    quas.setFitHeight(50);
    quas.setFitWidth(50);
    wex.setFitHeight(50);
    wex.setFitWidth(50);
    exort.setFitHeight(50);
    exort.setFitWidth(50);

    Circle orbit1 = new Circle();
    orbit1.setRotate(-90);
    orbit1.setRadius(100);
    orbit1.setCenterX(250);
    orbit1.setCenterY(250);
    PathTransition path1 = new PathTransition();
    path1.setPath(orbit1);
    path1.setNode(quas);
    path1.setDuration(Duration.seconds(5));
    path1.setCycleCount(Timeline.INDEFINITE);

    Circle orbit2 = new Circle();
    orbit2.setRotate(30);
    orbit2.setRadius(100);
    orbit2.setCenterX(250);
    orbit2.setCenterY(250);
    PathTransition path2 = new PathTransition();
    path2.setPath(orbit2);
    path2.setNode(wex);
    path2.setDuration(Duration.seconds(5));
    path2.setCycleCount(Timeline.INDEFINITE);

    Circle orbit3 = new Circle();
    orbit3.setRotate(150);
    orbit3.setRadius(100);
    orbit3.setCenterX(250);
    orbit3.setCenterY(250);
    PathTransition path3 = new PathTransition();
    path3.setPath(orbit3);
    path3.setNode(exort);
    path3.setDuration(Duration.seconds(5));
    path3.setCycleCount(Timeline.INDEFINITE);

    ComboBox<String> invoke = new ComboBox<String>();
    invoke.setEditable(false);
    invoke
        .getItems()
        .addAll(
            "Cold Snap",
            "Ghost Walk",
            "Tornado",
            "EMP",
            "Alacrity",
            "Chaos Meteor",
            "Sun Strike",
            "Forge Spirit",
            "Ice Wall",
            "Deafening Blast");
    invoke.setOnAction(
        e -> {
          switch (invoke.getValue()) {
            case "Cold Snap":
              path1.setNode(quas);
              path2.setNode(quas);
              path3.setNode(quas);
              break;
            case "Ghost Walk":
              path1.setNode(quas);
              path2.setNode(quas);
              path3.setNode(wex);
              break;
            case "Tornado":
              path1.setNode(wex);
              path2.setNode(wex);
              path3.setNode(quas);
              break;
            case "EMP":
              path1.setNode(wex);
              path2.setNode(wex);
              path3.setNode(wex);
              break;
            case "Alacrity":
              path1.setNode(wex);
              path2.setNode(wex);
              path3.setNode(exort);
              break;
            case "Chaos Meteor":
              path1.setNode(exort);
              path2.setNode(exort);
              path3.setNode(wex);
              break;
            case "Sun Strike":
              path1.setNode(exort);
              path2.setNode(exort);
              path3.setNode(exort);
              break;
            case "Forge Spirit":
              path1.setNode(exort);
              path2.setNode(exort);
              path3.setNode(quas);
              break;
            case "Ice Wall":
              path1.setNode(quas);
              path2.setNode(quas);
              path3.setNode(exort);
              break;
            case "Deafening Blast":
              path1.setNode(quas);
              path2.setNode(wex);
              path3.setNode(exort);
              break;
            default:
              path1.setNode(quas);
              path2.setNode(wex);
              path3.setNode(exort);
              break;
          }
        });

    path1.play();
    path2.play();
    path3.play();

    Pane pane = new Pane();
    pane.getChildren().addAll(quas, wex, exort, sun, invoke);
    stage.setScene(new Scene(pane, 500, 500));
    stage.setTitle("Spell Combinations");
    stage.show();
  }