diff --git a/src/main/java/edu/ntnu/stud/chaosgame/Main.java b/src/main/java/edu/ntnu/stud/chaosgame/Main.java index befa3b73005e671dbf7b0be5bff567f3c64df990..6378a7453e0f9c45c20dc5607c65037c5913ce3f 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/Main.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/Main.java @@ -17,16 +17,19 @@ public class Main { 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/templates/sierpinski.txt"; ChaosGameDescription description = null; // Declare description ChaosGame game = null; + ChaosGameDescriptionFactory factory = new ChaosGameDescriptionFactory(); + try { //ChaosGameDescription description = new ChaosGameFileHandler().readFromFile(path); //description = new ChaosGameDescription(minCoords, maxCoords, transforms); - description = new ChaosGameFileHandler().readFromFile(path); + //description = new ChaosGameFileHandler().readFromFile(path); + description = factory.getDescriptions().get(1); ChaosCanvas canvas = new ChaosCanvas(100, 100, description.getMinCoords(), description.getMaxCoords()); // Create canvas game = new ChaosGame(description, canvas); @@ -54,8 +57,8 @@ public class Main { 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."); + handler.writeToFile(description, "src/main/resources/descriptions/output/output_1.txt"); + System.out.println("Wrote to file output_1.txt."); } else { exit = true; diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosCanvas.java b/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosCanvas.java index f8826be960dba6b8ef3882661781e9b03590f7b3..5710a8cfdacfec1761104e3ce69e8bff25f6536f 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosCanvas.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosCanvas.java @@ -78,9 +78,21 @@ public class ChaosCanvas { [(int) transformCoordsToIndices.transform(point).getX1()]; } + /** + * Place a pixel on the canvas. + * + * @param point the point where the pixel is to be placed. + */ public void putPixel(Vector2D point) { - canvas[(int) transformCoordsToIndices.transform(point).getX0()] - [(int) transformCoordsToIndices.transform(point).getX1()] = 1; + int xOffset = (int) Math.abs(minCoords.getX0()); + int yOffset = (int) Math.abs(minCoords.getX1()); + + int xIndex = (int) transformCoordsToIndices.transform(point).getX0() + xOffset; + int yIndex = (int) transformCoordsToIndices.transform(point).getX1() + yOffset; + + if (xIndex >= 0 && xIndex < width && yIndex >= 0 && yIndex < height) { + canvas[xIndex][yIndex] = 1; + } } /** diff --git a/src/main/resources/descriptions/factory/desc_2.txt b/src/main/resources/descriptions/factory/desc_2.txt index e98ca28363edecbfbb6f8cd7b0f4b3a80b6a3006..989c78f1c5f9d74a09dd8141b766ce3faad24c87 100644 --- a/src/main/resources/descriptions/factory/desc_2.txt +++ b/src/main/resources/descriptions/factory/desc_2.txt @@ -1,6 +1,7 @@ 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 +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 diff --git a/src/main/resources/descriptions/Sierpinski.txt b/src/main/resources/descriptions/output/output_1.txt similarity index 100% rename from src/main/resources/descriptions/Sierpinski.txt rename to src/main/resources/descriptions/output/output_1.txt diff --git a/src/main/resources/descriptions/output.txt b/src/main/resources/descriptions/templates/sierpinski.txt similarity index 100% rename from src/main/resources/descriptions/output.txt rename to src/main/resources/descriptions/templates/sierpinski.txt