diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 7ddfc9ed476345b09db3e8fdf464a62bb2ccfa9b..574de4568e21706c1ac832f7025a60df46d8ae69 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -8,5 +8,6 @@ </component> <component name="VcsDirectoryMappings"> <mapping directory="" vcs="Git" /> + <mapping directory="$PROJECT_DIR$/idatt2003" vcs="Git" /> </component> </project> \ No newline at end of file diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameButtonController.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameButtonController.java index d77f154729fdd022faf2aa77ca3e8cc66b71e490..f34f7afcacb664f4bd1d72ddf4395068d51e65ed 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameButtonController.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameButtonController.java @@ -11,7 +11,7 @@ public class ChaosGameButtonController { private final Timeline timeline; public ChaosGameButtonController(ChaosGameGUIView view, Button startButton, Button stopButton, Button newButton, Button clearButton) { - this.timeline = new Timeline(new KeyFrame(Duration.seconds(0.01), event -> view.drawChaosGame(10))); + this.timeline = new Timeline(new KeyFrame(Duration.seconds(0.05), event -> view.drawChaosGame())); this.timeline.setCycleCount(Timeline.INDEFINITE); startButton.setOnAction(event -> timeline.play()); stopButton.setOnAction(event -> timeline.stop()); diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGame.java b/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGame.java index 0823fa7965a3151398a5cc9ac5addce4301e5b5d..c9e34d378a86ad8e1994c9069e0ea14c58164d8b 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGame.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGame.java @@ -60,8 +60,10 @@ public class ChaosGame { public void runSteps(int n) { for (int i = 0; i < n; i++) { int j = this.random.nextInt(0, this.numOfTransforms); + //System.out.println("Before transform: " + currentPoint.getX0() + " " + currentPoint.getX1()); + this.currentPoint = this.description.getTransforms().get(j).transform(currentPoint); - //System.out.println(currentPoint.getX0() + " " + currentPoint.getX1()); + //System.out.println("After transform: " + currentPoint.getX0() + " " + currentPoint.getX1()); this.canvas.putPixel(currentPoint); } //this.canvas.printCanvas(); diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGameFileHandler.java b/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGameFileHandler.java index 544ced9e628b644a2c59fe20e4d73d09849985e8..9bd2532e5c196734e9fae6697f5b3bcb3acb3a69 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGameFileHandler.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGameFileHandler.java @@ -97,11 +97,13 @@ public class ChaosGameFileHandler { double cReal = scanner.nextDouble(); double cImag = scanner.nextDouble(); Complex complex = new Complex(cReal,cImag); - JuliaTransform juliaTransform = new JuliaTransform(complex,1); - transforms.add(juliaTransform); + JuliaTransform juliaTransform1 = new JuliaTransform(complex,1); + JuliaTransform juliaTransform2 = new JuliaTransform(complex,-1); + transforms.add(juliaTransform1); + transforms.add(juliaTransform2); } - } else{throw new IllegalStateException("Invalid Chaos Game, expected 'Affine2D' or 'Juli'.");} + } else{throw new IllegalStateException("Invalid Chaos Game, expected 'Affine2D' or 'Julia'.");} } catch (IOException e) { throw new IOException("Failure to read file", e); } diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/transformations/JuliaTransform.java b/src/main/java/edu/ntnu/stud/chaosgame/model/transformations/JuliaTransform.java index c6cf7e0b7cfbb2b2147f2185d79f30b90a53cfc0..909c4f9ad64fbf37357a2e044aef484e948602ac 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/transformations/JuliaTransform.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/model/transformations/JuliaTransform.java @@ -51,13 +51,16 @@ public class JuliaTransform extends Transform2D { System.out.println("Sign is zero. No transformation performed"); return new Complex(point.getX0(),point.getX1()); } - return new Complex(temp1.getX0(), temp1.getX1()).sqrt(); - } + Complex sqrtResult = new Complex(temp1.getX0(), temp1.getX1()).sqrt(); + //System.out.println("Input to sqrt: " + temp1.getX0() + temp1.getX1() + ", Output: " + sqrtResult.getX0() + sqrtResult.getX1()); // Debug line + + return sqrtResult; } /** * Getter method to use with {@link ChaosGameFileHandler} * @return The complex number used in the transformation. */ public Complex getC1(){return this.c1;} + } diff --git a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java index 807ff4ef63ff5c2ce52baee129bbf8a223308a75..0cbf217f6171dfd759053e65a8e4301ffc1d10c1 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java @@ -64,17 +64,17 @@ public class ChaosGameGUIView { //TEMPORARY CODE to test Chaos Games in GUI ChaosGameDescriptionFactory factory = new ChaosGameDescriptionFactory(); - ChaosGameDescription description = factory.getDescriptions().get(2); + ChaosGameDescription description = factory.getDescriptions().get(1); ChaosCanvas canvas = new ChaosCanvas(1000, 1000, description.getMinCoords(), description.getMaxCoords()); game = new ChaosGame(description, canvas); } - public void drawChaosGame(int numLines){ + public void drawChaosGame(){ ChaosCanvas canvas = game.getCanvas(); - game.runSteps(2000); + game.runSteps(100000); // Test implementation for drawing fractals int[][] betaArray = canvas.getCanvasArray(); diff --git a/src/main/resources/descriptions/factory/desc_2.txt b/src/main/resources/descriptions/factory/desc_2.txt index 989c78f1c5f9d74a09dd8141b766ce3faad24c87..6985707d20e4faf7b2e3b0959ceccbc4ca6bd632 100644 --- a/src/main/resources/descriptions/factory/desc_2.txt +++ b/src/main/resources/descriptions/factory/desc_2.txt @@ -1,7 +1,7 @@ Affine2D -0.0, 0.0 -1.0, 1.0 -0.0, 0.0, 0.0, 0.16, 0.0, 0.0 -0.85, 0.04, -0.04, 0.85, 0.0, 1.6 -0.2, -0.26, 0.23, 0.22, 0.0, 0.16 --0.15, 0.28, 0.26, 0.24, 0, 0.44 +-2.65, 0 +2.65, 10 +0, 0, 0, .16, 0, 0 +.85, .04, -.04, .85, 0, 1.6 +.2, -.26, .23, .22, 0, 1.6 +-.15, .28, .26, .24, 0, .44 \ No newline at end of file diff --git a/src/main/resources/descriptions/factory/desc_3.txt b/src/main/resources/descriptions/factory/desc_3.txt index e98ca28363edecbfbb6f8cd7b0f4b3a80b6a3006..ed3fd5ad62576dc39c8ba5fe1f30bc2780a02381 100644 --- a/src/main/resources/descriptions/factory/desc_3.txt +++ b/src/main/resources/descriptions/factory/desc_3.txt @@ -1,6 +1,4 @@ -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 +Julia +-1.6, -1 +1.6, 1 +-.74543, .11301 \ No newline at end of file