import ch.aplu.turtle.Options; import ch.aplu.turtle.Playground; import ch.aplu.turtle.Turtle; 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) { PythagorasTree.PythagorasTreeVariant variant; Scanner scanner = new Scanner(System.in); if (input != null) variant = variantFromString(input); else variant = variantInput(scanner); double size = squareSizeInput(scanner); int loopSize = loopSizeInput(scanner); int depth = depthInput(scanner); double angle = 45; if (variant == PythagorasTree.PythagorasTreeVariant.AsymetricPythagorasTree) angle = angleInput(scanner); for (int i = 0; i < loopSize; i++) { new PythagorasTreeQueue(variant, new PythagorasTriangleList(variant, depth, angle), newTurtle(), size, 0, depth); } } public static PythagorasTree.PythagorasTreeVariant variantFromString(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("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 variant = PythagorasTree.PythagorasTreeVariant.unselected; return variant; } public static void playgroundSettings() { Scanner scanner = new Scanner(System.in); Options.setFrameTitle("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 = variantFromString(variantString); } System.out.println(variant); return variant; } public static void variantHelp() { System.out.println("SymetricPythagorasTree:"); 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:"); 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:"); 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("PisanoPythagorasTreeOne:"); 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 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 Fibonacci Numbers."); System.out.println("The angles of this variant calculated like this: "); System.out.println("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:"); System.out.println(""); System.out.println("The angles of this variant calculated like this: "); System.out.println("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:"); System.out.println(""); System.out.println("The angles of this variant calculated like this: "); System.out.println("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:"); System.out.println(""); System.out.println("The angles of this variant calculated like this: "); System.out.println("Fibonacci number of the Level modulo 31 plus 30"); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("PisanoPythagorasTreeFive:"); System.out.println(""); System.out.println("The angles of this variant calculated like this: "); System.out.println("Fibonacci number of the Level modulo 9 multiplied by 4 plus 29"); System.out.println(""); System.out.println(""); System.out.println(""); } }