package Fractals; import Fractals.PythagorasTree.PythagorasTree; import ch.aplu.turtle.Options; import ch.aplu.turtle.Playground; import ch.aplu.turtle.Turtle; import Fractals.PythagorasTree.*; import java.awt.*; import java.util.Scanner; /** * Created by Christian on 10.02.2015. */ public class Main { public static void main(String[] args) { playgroundSettings(); while (true) { if (args.length > 0) newPythagorasTree(args[0]); else newPythagorasTree(null); } } public static Turtle newTurtle() { Playground playground = new Playground(); playground.setAntiAliasing(true); playground.setAutoscrolls(true); playground.setPreferredSize(new Dimension(2160, 1440)); playground.setMinimumSize(new Dimension(2160, 1440)); playground.add(new Turtle(Color.GREEN)); Turtle turtle = playground.getTurtle(0); turtle.setFillColor(Color.BLACK).fill(); turtle.setPenColor(Color.GREEN); turtle.hideTurtle(); turtle.penUp(); turtle.right(180); turtle.forward(350); turtle.left(90); turtle.forward(50); turtle.left(90); turtle.penDown(); return turtle; } public static void newPythagorasTree(String input) { PythagorasTreeSeed seed; if (input != null) { seed = getSeedFromArg(input); } else { seed = getSeedFromInput(); } double size = seed.size; int loopSize = seed.loopSize; int depth = seed.depth; double angle = seed.angle; PythagorasTree.PythagorasTreeVariant variant = seed.variant; for (int i = 0; i < loopSize; i++) { new PythagorasTreeQueue(variant, new PythagorasTriangleList(variant, depth, angle), newTurtle(), size, 0, depth); } } private static PythagorasTreeSeed getSeedFromInput() { PythagorasTree.PythagorasTreeVariant variant; Scanner scanner = new Scanner(System.in); variant = variantInput(scanner); double size = squareSizeInput(scanner); int loopSize = loopSizeInput(scanner); int depth = depthInput(scanner); double angle; switch (variant) { case AsymetricPythagorasTree: angle = angleInput(scanner); break; default: angle = 45; break; } PythagorasTreeSeed seed = new PythagorasTreeSeed(size, loopSize, depth, angle, variant); return seed; } public static PythagorasTreeSeed getSeedFromArg(String input) { String[] splitInput = input.split("_"); PythagorasTree.PythagorasTreeVariant variant; variant = variantFromArg(splitInput[0]); double size = Double.parseDouble(splitInput[1]); int loopSize = Integer.parseInt(splitInput[2]); int depth = Integer.parseInt(splitInput[3]); double angle; switch (variant) { case AsymetricPythagorasTree: angle = Double.parseDouble(splitInput[4]); break; default: angle = 45; break; } PythagorasTreeSeed seed = new PythagorasTreeSeed(size, loopSize, depth, angle, variant); return seed; } public static PythagorasTree.PythagorasTreeVariant variantFromInput(String input) { PythagorasTree.PythagorasTreeVariant variant; if (input.equalsIgnoreCase("SymetricPythagorasTree")) { variant = PythagorasTree.PythagorasTreeVariant.SymetricPythagorasTree; } else if (input.equalsIgnoreCase("AsymetricPythagorasTree")) { variant = PythagorasTree.PythagorasTreeVariant.AsymetricPythagorasTree; } else if (input.equalsIgnoreCase("RegularRandomPythagorasTree")) { variant = PythagorasTree.PythagorasTreeVariant.RegularRandomPythagorasTree; } else if (input.equalsIgnoreCase("RandomPythagorasTree")) { variant = PythagorasTree.PythagorasTreeVariant.RandomPythagorasTree; } else if (input.equalsIgnoreCase("PisanoPythagorasTreeOne")) { variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeOne; } else if (input.equalsIgnoreCase("PisanoPythagorasTreeTwo")) { variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeTwo; } else if (input.equalsIgnoreCase("PisanoPythagorasTreeThree")) { variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeThree; } else if (input.equalsIgnoreCase("PisanoPythagorasTreeFour")) { variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeFour; } else if (input.equalsIgnoreCase("PisanoPythagorasTreeFive")) { variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeFive; } else if (input.equalsIgnoreCase("KilianEhrmannPythagorasTree")) { variant = PythagorasTree.PythagorasTreeVariant.KilianEhrmannPythagorasTree; } else variant = variantFromArg(input); return variant; } public static PythagorasTree.PythagorasTreeVariant variantFromArg(String input) { PythagorasTree.PythagorasTreeVariant variant; if (input.equalsIgnoreCase("1")) { variant = PythagorasTree.PythagorasTreeVariant.SymetricPythagorasTree; } else if (input.equalsIgnoreCase("2")) { variant = PythagorasTree.PythagorasTreeVariant.AsymetricPythagorasTree; } else if (input.equalsIgnoreCase("31")) { variant = PythagorasTree.PythagorasTreeVariant.RegularRandomPythagorasTree; } else if (input.equalsIgnoreCase("32")) { variant = PythagorasTree.PythagorasTreeVariant.RandomPythagorasTree; } else if (input.equalsIgnoreCase("41")) { variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeOne; } else if (input.equalsIgnoreCase("42")) { variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeTwo; } else if (input.equalsIgnoreCase("43")) { variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeThree; } else if (input.equalsIgnoreCase("44")) { variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeFour; } else if (input.equalsIgnoreCase("45")) { variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeFive; } else if (input.equalsIgnoreCase("5")) { variant = PythagorasTree.PythagorasTreeVariant.KilianEhrmannPythagorasTree; } else variant = PythagorasTree.PythagorasTreeVariant.unselected; return variant; } public static void playgroundSettings() { Scanner scanner = new Scanner(System.in); Options.setFrameTitle("Fractals/PythagorasTree"); System.out.println("How wide should the window be?"); int width = Integer.parseInt(scanner.nextLine()); System.out.println("How high should the window be?"); int height = Integer.parseInt(scanner.nextLine()); Options.setPlaygroundSize(width, height); Options.setFramePosition(0, 0); } public static Double squareSizeInput(Scanner scanner) { System.out.println("Size of First Square:"); return Double.parseDouble(scanner.nextLine()); } public static Integer loopSizeInput(Scanner scanner) { System.out.println("Create Loop? Type '1' for no loop and any larger number for a loop of that length:"); return Integer.parseInt(scanner.nextLine()); } public static Integer depthInput(Scanner scanner) { System.out.println("How many levels should the tree be deep?"); return Integer.parseInt(scanner.nextLine()); } public static Double angleInput(Scanner scanner) { System.out.println("What angle should the triangles of the tree have?"); System.out.println("The angle put into here will be used as the left angle."); return Double.parseDouble(scanner.nextLine()); } public static PythagorasTree.PythagorasTreeVariant variantInput(Scanner scanner) { PythagorasTree.PythagorasTreeVariant variant = PythagorasTree.PythagorasTreeVariant.unselected; while (variant == PythagorasTree.PythagorasTreeVariant.unselected) { System.out.println("No variant selected! Type in variant (To get the variants, type in 'help'):"); String variantString = scanner.nextLine(); if (variantString.equals("help")) variantHelp(); variant = variantFromInput(variantString); } System.out.println(variant); return variant; } public static void variantHelp() { System.out.println("SymetricPythagorasTree (1):"); System.out.println(""); System.out.println("This creates a normal symetric Pythagoras Tree."); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("AsymetricPythagorasTree (2):"); System.out.println(""); System.out.println("This creates an asymetric Pythagoras Tree."); System.out.println("The used angle will be adjustable later."); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("RegularRandomPythagorasTree (3.1):"); System.out.println(""); System.out.println("This creates an asymetric Pythagoras Tree."); System.out.println("Each level of the tree will have it's own randomly generated angle."); System.out.println("The generated angles will be between 20 and 70 degree."); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("RandomPythagorasTree (3.2):"); System.out.println(""); System.out.println("This creates an asymetric Pythagoras Tree."); System.out.println("Each triangle of the tree will have it's own randomly generated angle."); System.out.println("The generated angles will be between 20 and 70 degree."); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("PisanoPythagorasTreeOne (4.1):"); System.out.println(""); System.out.println("This creates an asymetric Pythagoras Tree."); System.out.println("The angles used in this tree are generated from the Fractals.NumberCalculation.Fibonacci Numbers."); System.out.println("This (and the following variants) are similar to the regular random trees, "); System.out.println("just with angles generated from the Fractals.NumberCalculation.Fibonacci Numbers."); System.out.println("The angles of this variant calculated like this: "); System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 4 multiplied by 10 plus 30"); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("PisanoPythagorasTreeTwo: (4.2)"); System.out.println(""); System.out.println("The angles of this variant calculated like this: "); System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 2 multiplied by 30 plus 30"); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("PisanoPythagorasTreeThree: (4.3)"); System.out.println(""); System.out.println("The angles of this variant calculated like this: "); System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 7 multiplied by 5 plus 30"); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("PisanoPythagorasTreeFour: (4.4)"); System.out.println(""); System.out.println("The angles of this variant calculated like this: "); System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 31 plus 30"); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("PisanoPythagorasTreeFive: (4.5)"); System.out.println(""); System.out.println("The angles of this variant calculated like this: "); System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 9 multiplied by 4 plus 29"); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("KilianEhrmannPythagorasTree: (5)"); System.out.println(""); System.out.println("The angles of this variant calculated like this: "); System.out.println("(Don't ask why, just one of my classmates having fun...) "); System.out.println("double result_1;\n" + " double result_2;\n" + " result_1 = 100000000*Math.pow(index,(1/13));\n" + " result_2 = 70000%index;\n" + " result_2 = Math.cos(Math.tan(result_2));\n" + " result_2 = index - result_2;\n" + " result_2 *= index + (1 / ( Math.pow(index, (1/17.3))));\n" + " result_2 = Math.pow(result_2, (1/index));\n" + " result_1 /= result_2;\n" + " result_1 = result_1 % index;\n" + " result_1 = result_1 % 30;\n" + " result_1 += 30;\n" + " return result_1;"); System.out.println(""); System.out.println(""); System.out.println(""); } }