Search in sources :

Example 1 with Polygon

use of javafx.scene.shape.Polygon in project aima-java by aimacode.

the class NQueensViewCtrl method update.

/** Updates the view. */
public void update(NQueensBoard board) {
    int size = board.getSize();
    if (queens.length != size * size) {
        gridPane.getChildren().clear();
        gridPane.getColumnConstraints().clear();
        gridPane.getRowConstraints().clear();
        queens = new Polygon[size * size];
        RowConstraints c1 = new RowConstraints();
        c1.setPercentHeight(100.0 / size);
        ColumnConstraints c2 = new ColumnConstraints();
        c2.setPercentWidth(100.0 / size);
        for (int i = 0; i < board.getSize(); i++) {
            gridPane.getRowConstraints().add(c1);
            gridPane.getColumnConstraints().add(c2);
        }
        for (int i = 0; i < queens.length; i++) {
            StackPane field = new StackPane();
            queens[i] = createQueen();
            field.getChildren().add(queens[i]);
            int col = i % size;
            int row = i / size;
            field.setBackground(new Background(new BackgroundFill((col % 2 == row % 2) ? Color.WHITE : Color.LIGHTGRAY, null, null)));
            gridPane.add(field, col, row);
        }
    }
    double scale = 0.2 * gridPane.getWidth() / gridPane.getColumnConstraints().size();
    for (int i = 0; i < queens.length; i++) {
        Polygon queen = queens[i];
        queen.setScaleX(scale);
        queen.setScaleY(scale);
        XYLocation loc = new XYLocation(i % size, i / size);
        if (board.queenExistsAt(loc)) {
            queen.setVisible(true);
            queen.setFill(board.isSquareUnderAttack(loc) ? Color.RED : Color.BLACK);
        } else {
            queen.setVisible(false);
        }
    }
}
Also used : Background(javafx.scene.layout.Background) XYLocation(aima.core.util.datastructure.XYLocation) ColumnConstraints(javafx.scene.layout.ColumnConstraints) BackgroundFill(javafx.scene.layout.BackgroundFill) Polygon(javafx.scene.shape.Polygon) StackPane(javafx.scene.layout.StackPane) RowConstraints(javafx.scene.layout.RowConstraints)

Example 2 with Polygon

use of javafx.scene.shape.Polygon in project Gargoyle by callakrsos.

the class PolygonEx method start.

@Override
public void start(Stage stage) {
    Pane g = new Pane();
    ScrollPane convert = XY.convert(g);
    {
        //한 점의 좌표가 주어진경우
        double x = 150;
        double y = 150;
        //빗변의 길이
        double r = 100;
        double degree = Math.atan2(y, x);
        double x1 = x + (r / Math.tan(degree));
        double y1 = y;
        double x2 = x1;
        double y2 = y + y - r;
        Polygon polygon = new Polygon();
        polygon.setLayoutX(x);
        polygon.setLayoutY(x);
        polygon.getPoints().addAll(new Double[] { x, y, x1, y1, x2, y2 });
        g.getChildren().add(polygon);
        g.getChildren().add(new Line(1, 1, 10, 10));
    }
    {
        //한 점의 좌표가 주어진경우
        double x = 150;
        double y = 150;
        //빗변의 길이
        double r = 100;
        double degree = Math.atan2(y, x);
        double x1 = x + (r / Math.tan(degree));
        double y1 = y;
        double x2 = x1;
        double y2 = y + r;
        Polygon polygon = new Polygon();
        polygon.getPoints().addAll(new Double[] { x, y, x1, y1, x2, y2 });
        g.getChildren().add(polygon);
    }
    //		Line line = new Line();
    //		line.setStartX(x);
    //		line.setStartY(y);
    //		line.setEndX(x2);
    //		line.setEndY(y2);
    //
    //		Text text = new Text("x : " + x + " y : " + y);
    //		text.setX(x);
    //		text.setY(y - 20);
    //
    //		Text text1 = new Text("x1 : " + x1 + " y1 : " + y1);
    //		text1.setX(x1);
    //		text1.setY(y1 - 20);
    //
    //		Text text2 = new Text("x2 : " + x2 + " y2 : " + y2);
    //		text2.setX(x2);
    //		text2.setY(y2 - 20);
    //		g.getChildren().addAll(polygon, text, text1, text2);
    Scene scene = new Scene(convert, 1800, 900);
    stage.setScene(scene);
    stage.show();
}
Also used : Line(javafx.scene.shape.Line) ScrollPane(javafx.scene.control.ScrollPane) Polygon(javafx.scene.shape.Polygon) Scene(javafx.scene.Scene) ScrollPane(javafx.scene.control.ScrollPane) Pane(javafx.scene.layout.Pane)

Aggregations

Polygon (javafx.scene.shape.Polygon)2 XYLocation (aima.core.util.datastructure.XYLocation)1 Scene (javafx.scene.Scene)1 ScrollPane (javafx.scene.control.ScrollPane)1 Background (javafx.scene.layout.Background)1 BackgroundFill (javafx.scene.layout.BackgroundFill)1 ColumnConstraints (javafx.scene.layout.ColumnConstraints)1 Pane (javafx.scene.layout.Pane)1 RowConstraints (javafx.scene.layout.RowConstraints)1 StackPane (javafx.scene.layout.StackPane)1 Line (javafx.scene.shape.Line)1