diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 574de4568e21706c1ac832f7025a60df46d8ae69..7ddfc9ed476345b09db3e8fdf464a62bb2ccfa9b 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -8,6 +8,5 @@ </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/transformations/AffineTransform2D.java b/src/main/java/edu/ntnu/stud/chaosgame/transformations/AffineTransform2D.java index a3ff094ffa1756328ee2ca28a7b27d01bd8cf8ce..1df2ee410615aacbe0081e71563c623910fafe0f 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/transformations/AffineTransform2D.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/transformations/AffineTransform2D.java @@ -14,6 +14,9 @@ public class AffineTransform2D extends Transform2D { * The matrix{@link Matrix2x2} which performs the matrix-multiplication part of the affine transformation. */ private Matrix2x2 matrix; + + + /** * The vector{@link Vector2D} which is added as part of the affine transformation. */ diff --git a/src/main/java/edu/ntnu/stud/chaosgame/transformations/ChaosCanvas.java b/src/main/java/edu/ntnu/stud/chaosgame/transformations/ChaosCanvas.java new file mode 100644 index 0000000000000000000000000000000000000000..c0836a7beab0c098ee1de823c40c7d807a875075 --- /dev/null +++ b/src/main/java/edu/ntnu/stud/chaosgame/transformations/ChaosCanvas.java @@ -0,0 +1,101 @@ +package edu.ntnu.stud.chaosgame.transformations; + +import edu.ntnu.stud.chaosgame.model.Matrix2x2; +import edu.ntnu.stud.chaosgame.model.Vector2D; + + +/** + * Class representing the canvas for the display of the chaos game. + */ +public class ChaosCanvas { + + /** + * Table representing the canvas. + */ + private int[][] canvas; + + /** + * Width of the canvas + */ + private int width; + + /** + * Height of the canvas + */ + private int height; + + /** + * The minimum coordinates of the canvas. + */ + private Vector2D minCoords; + + /** + * The maximum coordinates of the canvas. + */ + private Vector2D maxCoords; + + /** + * Affine transformation for converting coordinates to canvas indices. + */ + private AffineTransform2D transformCoordsToIndices; + + /** + * Parameterized constructor for the class. + * + * @param width width of the canvas + * @param height height of the canvas + * @param minCoords minimum coordinates of the canvas + * @param maxCoords maximum coordinates of the canvas + */ + public ChaosCanvas(int width, int height, Vector2D minCoords, Vector2D maxCoords) { + this.width = width; + this.height = height; + this.minCoords = minCoords; + this.maxCoords = maxCoords; + + this.canvas = new int[width][height]; + + // Define the affine transformation that maps coordinates to indices in the canvas. + this.transformCoordsToIndices = new AffineTransform2D( + new Matrix2x2(0, height - 1, width - 1, 0), + new Vector2D((((height - 1) * maxCoords.getX0()) / maxCoords.getX1()), + ((width - 1) * minCoords.getX1()) / maxCoords.getX1()) + ); + } + + /** + * Get a pixel located at a point. + * + * @param point point at which the pixel is located + * @return the pixel + */ + public int getPixel(Vector2D point) { + return canvas[(int) transformCoordsToIndices.transform(point).getX0()] + [(int) transformCoordsToIndices.transform(point).getX1()]; + } + + public void putPixel(Vector2D point) { + canvas[(int) transformCoordsToIndices.transform(point).getX0()] + [(int) transformCoordsToIndices.transform(point).getX1()] = 1; + } + + /** + * Get the canvas array. + * @return the canvas array + */ + public int[][] getCanvasArray() { + return canvas; + } + + /** + * Clear the canvas of all content. + */ + public void clearCanvas() { + for (int i = 0; i < width; i++) { + for (int j = 0; j < height; j++) { + canvas[i][j] = 0; + } + } + } + +}