package UE10_070125_Rekursion3;


import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class UE10_Rekursion3_Aufgabe1 extends Application {

    static final int canvasWidth = 1000;
    static final int canvasHeight = 500;

    Canvas canvas = new Canvas(canvasWidth, canvasHeight);
    GraphicsContext gc = canvas.getGraphicsContext2D();

    public static void main(String[] args) {
        //Aufgabe 1
        Application.launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setResizable(false);
        primaryStage.setScene(new Scene(new BorderPane(canvas)));
        primaryStage.show();
        gc.setFill(Color.LIGHTGRAY);
        gc.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
        int side = 100;
        drawRec((canvasWidth - side) / 2, canvasHeight - side - 10, side);
    }

    private void drawRec(int xCord, int yCord, int side) {
        if (side < 2) return;
        gc.setFill(Color.WHITE);
        gc.fillRect(xCord, yCord, side, side);
        gc.setStroke(Color.BLACK);
        gc.setLineWidth(1);
        gc.strokeRect(xCord, yCord, side, side);
        int newSide = side * 3 / 4;
        drawRec(xCord - newSide, yCord - newSide, side / 2);
        drawRec(xCord + side * 5 / 4, yCord - newSide, side / 2);
    }
}