diff --git a/src/main/java/edu/ntnu/stud/chaosgame/Main.java b/src/main/java/edu/ntnu/stud/chaosgame/Main.java index 2d0d60704c296c1e51d6caf77ae428e0dd34474d..73020f68b8afe484c5ef5004578574d32aa72e94 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/Main.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/Main.java @@ -8,17 +8,21 @@ import edu.ntnu.stud.chaosgame.model.handling.ChaosCanvas; import edu.ntnu.stud.chaosgame.model.handling.ChaosGame; import edu.ntnu.stud.chaosgame.model.transformations.AffineTransform2D; import edu.ntnu.stud.chaosgame.model.transformations.Transform2D; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.Scanner; /** * Main class for the Chaos Game application. */ public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws IOException { + Scanner sc = new Scanner(System.in); System.out.println("Hi"); - String path = "src/main/resources/descriptions/Sierpinski.txt"; + String path = "src/main/resources/descriptions/sierpinski.txt"; ChaosGameDescription description = null; // Declare description @@ -34,7 +38,34 @@ public class Main { } catch (Exception e) { System.out.println(e.getMessage()); // TODO: Alter error handling } - game.runSteps(100000); + + boolean exit = false; + + // While loop for simple cli-app. + while (!exit) { + + System.out.println("What would you like to do? Type 1 for displaying fractal, " + + "or anything else for ending the program"); + if (Objects.equals(sc.next(), "1")) { + game.runSteps(100000); + System.out.println( + "What would you like to do? Type 1 for saving the fractal, anything else for ending the program"); + + if (Objects.equals(sc.next(), "1")) { + ChaosGameFileHandler handler = new ChaosGameFileHandler(); + handler.writeToFile(description, "src/main/resources/descriptions/output.txt"); + System.out.println("Wrote to file output.txt."); + } + else { + exit = true; + } + } + else { + exit = true; + } + } + System.out.println("Terminated program."); + diff --git a/src/main/resources/descriptions/output.txt b/src/main/resources/descriptions/output.txt new file mode 100644 index 0000000000000000000000000000000000000000..e98ca28363edecbfbb6f8cd7b0f4b3a80b6a3006 --- /dev/null +++ b/src/main/resources/descriptions/output.txt @@ -0,0 +1,6 @@ +Affine2D +0.0, 0.0 +1.0, 1.0 +0.5, 0.0, 0.0, 0.5, 0.0, 0.0 +0.5, 0.0, 0.0, 0.5, 0.25, 0.5 +0.5, 0.0, 0.0, 0.5, 0.5, 0.0