Untitled

 avatar
unknown
plain_text
2 years ago
8.8 kB
5
Indexable
package de.tum.in.ase;

import javafx.application.Application;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.ArrayList;
import java.util.List;

public class TUMTriangle extends Application {

    private static final Color PAINT_BLUE = Color.valueOf("#316EB2");
    private static final Color PAINT_WHITE = Color.valueOf("#ffffff");
    private static final Color OK_ = Color.valueOf("#f72d2d");
    private @NonNull List<Triangle> triangles = new ArrayList<>();

    /**
     * Creates the TUM triangle recursively by adding the generated triangles to the triangles
     * to the triangles attribute in the object.
     * @param top The offset from the top
     * @param left The offset from the left
     * @param height The height of the triangle
     * @param depth The recursion depth
     */
    public void createTUMTriangle(double top, double left, double height, int depth) {
        // TODO: Task 1: create the TUM triangle
//        if (depth < 2) {
//            if (depth > 0) {
//                if (depth == 1) {
//                    Triangle blueTriangle = new Triangle(new Point(top, left), new Point(top, top + height), new Point(height, height / 2), PAINT_BLUE);
//                    triangles.add(blueTriangle);
//                }
//
//                triangles.addAll( paintWhiteTriangle(top, left,height,depth));
//            }
//            createTUMTriangle(top, left,height, depth + 1);
//        }

        int temp = depth;
        Triangle blueTriangle = new Triangle(new Point(top, left), new Point(top, top + height), new Point(height* Math.sqrt(3) / 2, height / 2), PAINT_BLUE);

        if (depth == 0) {
            return;
        }
        if (depth > 0){
            triangles.add(blueTriangle);

            for (int x = 0; x < Math.pow(3, depth - 1); x++) {
                double p1x = 0;
                double p1y = (height/Math.pow(2,1));
                double p2x = (Math.sqrt(3)/4)* height;
                double p2y = (height/Math.pow(2,2));
                double p3x = (Math.sqrt(3)/4) * height;
                double p3y = (3*height/Math.pow(2,0))/4;

                Point point1_1= new Point(0, (height/Math.pow(2,2)));
//            Point point2_1 = new Point( (Math.sqrt(3)/4) * height/2,(height/Math.pow(2,3)));//(height/2)/4
//            Point point3_1 = new Point( (Math.sqrt(3)/4) * height/2,(3*(height/Math.pow(2,1)))/4);//(3*(height/2))/4
//

                Point point1= new Point(p1x, p1y);
                Point point2 = new Point( p2x,p2y);
                Point point3 = new Point( p3x,p3y);
//
                Triangle whiteTriangle1 = new Triangle(point1,point2, point3, PAINT_WHITE);
                //Triangle whiteTriangle1 = new Triangle(new Point(top, left), new Point(top, top + height), new Point(height* Math.sqrt(3) / 2, height / 2), PAINT_BLUE);

                triangles.add(whiteTriangle1);
            }

            //createTUMTriangle(top, left, newHeight, depth - 1);


        }
        //if (depth == 4) {
        ///1
//            Triangle blueTriangle = new Triangle(new Point(top, left), new Point(top, top + height), new Point(height, height / 2), PAINT_BLUE);
//
//            Point point1= new Point(0, (height/Math.pow(2,1)));
//            Point point2 = new Point( (Math.sqrt(3)/4) * height,(height/Math.pow(2,2)));//(height/2)/2
//            Point point3 = new Point( (Math.sqrt(3)/4) * height,(3*height/Math.pow(2,0))/4);//(3*height)/4
//
//            Triangle whiteTriangle1 = new Triangle(point1,point2, point3, PAINT_WHITE);

//////2

//            Point point1_1= new Point(0, (height/Math.pow(2,2)));
//            Point point2_1 = new Point( (Math.sqrt(3)/4) * height/2,(height/Math.pow(2,3)));//(height/2)/4
//            Point point3_1 = new Point( (Math.sqrt(3)/4) * height/2,(3*(height/Math.pow(2,1)))/4);//(3*(height/2))/4
//
//            Triangle whiteTriangle2 = new Triangle(point1_1,point2_1, point3_1, PAINT_WHITE);
///3
//            Point point1_t= new Point(0, (height/Math.pow(2,3)));
//            Point point2_t = new Point( (Math.sqrt(3)/4) * height/2/2,(height/Math.pow(2,4)));//(height/2/2)/4
//            Point point3_t = new Point( (Math.sqrt(3)/4) * height/2/2,(3*(height/Math.pow(2,2)))/4);////(3*(height/2/2))/4
//
//            Triangle whiteTrianglet = new Triangle(point1_t,point2_t, point3_t, PAINT_WHITE);
////2
//            Point point1_2= new Point(0, (height/Math.pow(2,1))+(height/Math.pow(2,2))); //((height/2)+(height/2)/2)
//            Point point2_2 = new Point( (Math.sqrt(3)/4) * (height/2),((height/2)+(height/2)/2/2));
//            Point point3_2 = new Point( (Math.sqrt(3)/4) * (height/2),(height/Math.pow(2,1))+(height/Math.pow(2,2))+(height/Math.pow(2,3)));
            //((height/2)+(height/2)/2)+(((height/2)/2)/2)

//            Triangle whiteTriangle3 = new Triangle(point1_2,point2_2, point3_2, PAINT_WHITE);
//3
//            Point point1_t2= new Point(0, (height/Math.pow(2,1))+(height/Math.pow(2,2))+(height/Math.pow(2,3))); //((height/2)+(height/2)/2)+(height/2)/2/2)
//            Point point2_t2 = new Point( (Math.sqrt(3)/4) * (height/2/2),(height/2)+((height/2)/2)+ ((height/2)/2/2/2));
//            Point point3_t2 = new Point( (Math.sqrt(3)/4) * (height/2/2),(height/Math.pow(2,1))+(height/Math.pow(2,2))+(height/Math.pow(2,3))+(height/Math.pow(2,4)));
            //(height/2)+((height/2)/2)+(((height/2)/2)/2)+(((height/2)/2)/2/2)

//            Triangle whiteTrianglet2 = new Triangle(point1_t2,point2_t2, point3_t2, PAINT_WHITE);
//2
//            Point point1_3= new Point((Math.sqrt(3)/4) * height, (height/2));
//            Point point2_3 = new Point( (Math.sqrt(3)/4) * height + ((Math.sqrt(3)/4) * height/2),(3*(height/2))/4);
//            Point point3_3 = new Point( (Math.sqrt(3)/4) * height + ((Math.sqrt(3)/4) * height/2),((height/2)+(height/2)/2/2));

//            Triangle whiteTriangle4 = new Triangle(point1_3,point2_3, point3_3, PAINT_WHITE);
        ///test
//            Point point1_4= new Point((Math.sqrt(3)/4) * height + ((Math.sqrt(3)/4) * height/2), (height/2));
//            Point point2_4 = new Point( (Math.sqrt(3)/4) * height + ((Math.sqrt(3)/4) * height/2) + ((Math.sqrt(3)/4) * height/2/2),((3*(height/2))/4)); //no point in y
//            Point point3_4 = new Point( (Math.sqrt(3)/4) * height + ((Math.sqrt(3)/4) * height/2) + ((Math.sqrt(3)/4) * height/2/2),(height/2)+((height/2)/2/2/2));
//
//            Triangle whiteTriangle4t = new Triangle(point1_4,point2_4, point3_4, OK_);

//            triangles.add(blueTriangle);
//            triangles.add(whiteTriangle1);
//            triangles.add(whiteTriangle2);
//            triangles.add(whiteTrianglet);
//            triangles.add(whiteTriangle3);
//            triangles.add(whiteTrianglet2);
//            triangles.add(whiteTriangle4);
            //triangles.add(whiteTriangle4t);
           // triangles.addAll(paintWhiteTriangle(top, left, height, depth));
       // }
//        else {
//            double newHeight = height / 2;
//            createTUMTriangle(top, left, newHeight, depth - 1);
//            createTUMTriangle(top + newHeight, left + newHeight / 2, newHeight, depth - 1);
//            createTUMTriangle(top, left + newHeight, newHeight, depth - 1);
//        }

    }

    public ArrayList<Triangle> paintWhiteTriangle(double top, double left, double height, int depth) {
//        ArrayList <Triangle> whiteTriangleList = new ArrayList<>();
//        for (int x = 0; x < Math.pow(3, depth - 1); x++) {
//            height = height/2;
//            Triangle whiteTriangle = new Triangle(new Point(top, height), new Point(height, height/2 * 3), new Point(height, height/2), PAINT_WHITE);
//            whiteTriangleList.add(whiteTriangle);
//        }
//        return whiteTriangleList;
        ArrayList<Triangle> whiteTriangleList = new ArrayList<>();
        Triangle whiteTriangle = new Triangle(new Point(top, height), new Point(height, height / 2 * 3), new Point(height, height / 2), PAINT_WHITE);
        whiteTriangleList.add(whiteTriangle);
        return whiteTriangleList;
    }



    @Override
    public void start(Stage stage) {
        this.triangles = new ArrayList<>();

        SimplePad simplePad = new SimplePad(400 * Math.sqrt(3) / 2, 400);
        stage.setTitle("TUM triangle");
        stage.setScene(simplePad);
        stage.setResizable(true);//change false to true
        stage.show();

        createTUMTriangle(0, 0, 400, 2);

        for (Triangle triangle : triangles) {
            simplePad.drawTriangle(triangle);
        }
    }
}
Editor is loading...