Пример #1
0
  public void drawWhiteEdge(Edge e) {
    // Graphics
    GraphicsContext gc = kochPanel.getGraphicsContext2D();

    // Adjust edge for zoom and drag
    Edge e1 = edgeAfterZoomAndDrag(e);

    // Set line color
    gc.setStroke(Color.WHITE);

    // Set line width depending on level
    if (currentLevel <= 3) {
      gc.setLineWidth(2.0);
    } else if (currentLevel <= 5) {
      gc.setLineWidth(1.5);
    } else {
      gc.setLineWidth(1.0);
    }

    // Draw line
    gc.strokeLine(e1.X1, e1.Y1, e1.X2, e1.Y2);
  }
Пример #2
0
  @Override
  public void start(Stage primaryStage) {

    // Define grid pane
    GridPane grid;
    grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    // For debug purposes
    // Make de grid lines visible
    // grid.setGridLinesVisible(true);

    // Drawing panel for Koch fractal
    kochPanel = new Canvas(kpWidth, kpHeight);
    grid.add(kochPanel, 0, 4, 25, 1);

    // Labels to present number of edges for Koch fractal
    labelNrEdges = new Label("Nr edges:");
    labelNrEdgesText = new Label();
    grid.add(labelNrEdges, 0, 0, 4, 1);
    grid.add(labelNrEdgesText, 3, 0, 22, 1);

    // Labels to present time of calculation for Koch fractal
    labelCalc = new Label("Calculating:");
    labelCalcText = new Label();
    grid.add(labelCalc, 0, 1, 4, 1);
    grid.add(labelCalcText, 3, 1, 22, 1);

    // Labels to present time of drawing for Koch fractal
    labelDraw = new Label("Drawing:");
    labelDrawText = new Label();
    grid.add(labelDraw, 0, 2, 4, 1);
    grid.add(labelDrawText, 3, 2, 22, 1);

    // Label to present current level of Koch fractal
    labelLevel = new Label("Level: " + currentLevel);
    grid.add(labelLevel, 0, 6);

    // Button to increase level of Koch fractal
    Button buttonIncreaseLevel = new Button();
    buttonIncreaseLevel.setText("Increase Level");
    buttonIncreaseLevel.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            increaseLevelButtonActionPerformed(event);
          }
        });
    grid.add(buttonIncreaseLevel, 3, 6);

    // Button to decrease level of Koch fractal
    Button buttonDecreaseLevel = new Button();
    buttonDecreaseLevel.setText("Decrease Level");
    buttonDecreaseLevel.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            decreaseLevelButtonActionPerformed(event);
          }
        });
    grid.add(buttonDecreaseLevel, 5, 6);

    // Button to fit Koch fractal in Koch panel
    Button buttonFitFractal = new Button();
    buttonFitFractal.setText("Fit Fractal");
    buttonFitFractal.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            fitFractalButtonActionPerformed(event);
          }
        });
    grid.add(buttonFitFractal, 14, 6);

    // Add mouse clicked event to Koch panel
    kochPanel.addEventHandler(
        MouseEvent.MOUSE_CLICKED,
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            kochPanelMouseClicked(event);
          }
        });

    // Add mouse pressed event to Koch panel
    kochPanel.addEventHandler(
        MouseEvent.MOUSE_PRESSED,
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            kochPanelMousePressed(event);
          }
        });

    // Add mouse dragged event to Koch panel
    kochPanel.setOnMouseDragged(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            kochPanelMouseDragged(event);
          }
        });
    // Adding progress bars and their info
    Label LeftLabel = new Label("Left Progress");
    lblLeftCalc = new Label(". . . . .");
    grid.add(lblLeftCalc, 7, 10);
    grid.add(LeftLabel, 1, 5);
    grid.add(progressBarLeft, 2, 5);

    Label RightLabel = new Label("Right Progress");
    lblRightCalc = new Label(". . . . .");
    grid.add(lblRightCalc, 7, 11);
    grid.add(RightLabel, 1, 6);
    grid.add(progressBarRight, 2, 6);

    Label BottomLabel = new Label("Bottom Progress");
    lblBottomCalc = new Label(". . . . .");
    grid.add(lblBottomCalc, 7, 12);
    grid.add(BottomLabel, 1, 7);
    grid.add(progressBarBottom, 2, 7);

    // Create Koch manager and set initial level
    resetZoom();
    kochManager = new KochManager(this);
    kochManager.ChangeLevel(currentLevel);

    // Create the scene and add the grid pane
    Group root = new Group();
    Scene scene = new Scene(root, kpWidth + 50, kpHeight + 170);
    root.getChildren().add(grid);

    // Define title and assign the scene for main window
    primaryStage.setTitle("Koch Fractal");
    primaryStage.setScene(scene);
    primaryStage.show();
  }
Пример #3
0
 public void clearKochPanel() {
   GraphicsContext gc = kochPanel.getGraphicsContext2D();
   gc.clearRect(0.0, 0.0, kpWidth, kpHeight);
   gc.setFill(Color.BLACK);
   gc.fillRect(0.0, 0.0, kpWidth, kpHeight);
 }