diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7f4cb416c083d265558da75d457237d671..ba62b845c54f748f9ea0f0f7f9d34ef309002d6d 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="VcsDirectoryMappings"> +<<<<<<< HEAD <mapping directory="$PROJECT_DIR$" vcs="Git" /> +======= + <mapping directory="" vcs="Git" /> +>>>>>>> origin/main </component> </project> \ No newline at end of file diff --git a/src/main/java/org/example/chaosgame/controller/ChaosGameController.java b/src/main/java/org/example/chaosgame/controller/ChaosGameController.java index df747d710cc1e611b2c646f39f101b47cd310b5d..ead31676fc9474c2d777bf4472b85d1fd12025b3 100644 --- a/src/main/java/org/example/chaosgame/controller/ChaosGameController.java +++ b/src/main/java/org/example/chaosgame/controller/ChaosGameController.java @@ -22,6 +22,7 @@ import org.example.chaosgame.model.chaos.ChaosGameFileHandler; import org.example.chaosgame.model.chaos.ChaosGameType; import org.example.chaosgame.model.linalg.Complex; import org.example.chaosgame.model.linalg.Vector2D; +import org.example.chaosgame.model.linalg.Matrix2x2; import org.example.chaosgame.model.transformations.AffineTransform2D; import org.example.chaosgame.model.transformations.JuliaTransform; import org.example.chaosgame.model.transformations.Transform2D; @@ -107,6 +108,14 @@ public class ChaosGameController implements Observer, Subject, GameController { if (steps < 1 || steps > 10000000) { throw new NumberFormatException(); } + if (chaosGame.getDescription().getTransforms().getFirst() instanceof JuliaTransform && steps > 250000) { + AlertUtility.showErrorDialog("Invalid input", "Please enter a lower amount of steps for Julia transformations."); + return; + } + if (chaosGame.getTotalSteps() > Math.pow(10, 8)) { + AlertUtility.showErrorDialog("Invalid input", "The total number of steps is too high. Please reset the game."); + return; + } chaosGame.setSteps(steps); chaosGame.addTotalSteps(steps); chaosGame.runSteps(); @@ -214,14 +223,33 @@ public class ChaosGameController implements Observer, Subject, GameController { if (result.isPresent()) { Object fractalData = result.get(); - + List<Transform2D> transforms = new ArrayList<>(); if (fractalData instanceof List) { - List<AffineTransform2D> transformations = (List<AffineTransform2D>) fractalData; - List<Transform2D> transforms = new ArrayList<>(transformations); - updateChaosGame(new ChaosGameDescription( - new Vector2D(0, 0), - new Vector2D(1.0, 1.0), - transforms)); + List<List<String>> userInput = (List<List<String>>) fractalData; + for(List<String> input : userInput) { + try { + double a = Double.parseDouble(input.get(0)); + double b = Double.parseDouble(input.get(1)); + double c = Double.parseDouble(input.get(2)); + double d = Double.parseDouble(input.get(3)); + double x = Double.parseDouble(input.get(4)); + double y = Double.parseDouble(input.get(5)); + + if (a < -5 || a > 5 || b < -5 || b > 5 || c < -5 || c > 5 || + d < -5 || d > 5 || x < -5 || x > 5 || y < -5 || y > 5) { + throw new NumberFormatException(); + } else { + transforms.add(new AffineTransform2D(new Matrix2x2(a, b, c, d), new Vector2D(x, y))); + } + updateChaosGame(new ChaosGameDescription( + chaosGame.getDescription().getMinCoords(), + chaosGame.getDescription().getMaxCoords(), + transforms)); + } catch (NumberFormatException e) { + AlertUtility.showErrorDialog("Invalid input", "Please enter a valid number."); + } + } +// List<Transform2D> transforms = new ArrayList<>(transformations); } else if (fractalData instanceof Pair) { Pair<String, String> userInput = (Pair<String, String>) fractalData; try { // Check if the input is a valid number @@ -233,25 +261,13 @@ public class ChaosGameController implements Observer, Subject, GameController { "Please enter a double between -1 and 1. No letters are allowed."); } else { updateChaosGame(new ChaosGameDescription( - new Vector2D(-1.6, -1), - new Vector2D(1.6, 1.0), + chaosGame.getDescription().getMinCoords(), + chaosGame.getDescription().getMaxCoords(), List.of(new JuliaTransform(new Complex(real, imaginary), 1)))); } } catch (NumberFormatException e) { AlertUtility.showErrorDialog("Invalid input", "Please enter a valid number."); } - double real = Double.parseDouble(userInput.getKey()); - double imaginary = Double.parseDouble(userInput.getValue()); - - if (real < -1 || real > 1 || imaginary < -1 || imaginary > 1) { - AlertUtility.showErrorDialog("Invalid input", - "Please enter a double between -1 and 1. No letters are allowed."); - } else { - updateChaosGame(new ChaosGameDescription( - new Vector2D(-1.6, -1), - new Vector2D(1.6, 1.0), - List.of(new JuliaTransform(new Complex(real, imaginary), 1)))); - } } } } diff --git a/src/main/java/org/example/chaosgame/view/GamePage.java b/src/main/java/org/example/chaosgame/view/GamePage.java index 68944e8292504ffec1ed522b6b544896e838058f..8217f98513996bd19e21e588524516d3545d3cee 100644 --- a/src/main/java/org/example/chaosgame/view/GamePage.java +++ b/src/main/java/org/example/chaosgame/view/GamePage.java @@ -14,7 +14,7 @@ import org.example.chaosgame.model.chaos.ChaosCanvas; */ public abstract class GamePage extends BorderPane { protected final GraphicsContext gc; - private static final int COLOR_FACTOR = 6; + private static final int COLOR_FACTOR = 3; private static final int CANVAS_WIDTH = 1250; private static final int CANVAS_HEIGHT = 805; private static final int MAX_COLOR_VALUE = 255;