From 13f62b19f9432fe55fc60b026d5ed99059787231 Mon Sep 17 00:00:00 2001
From: stevenha <steveha@stud.ntnu.no>
Date: Wed, 13 Mar 2024 15:58:44 +0100
Subject: [PATCH 1/2] Created ChaosGame class, implemented constructor, getter
 method and method runSteps.

---
 .../java/edu/ntnu/idatt2003/ChaosGame.java    | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 src/main/java/edu/ntnu/idatt2003/ChaosGame.java

diff --git a/src/main/java/edu/ntnu/idatt2003/ChaosGame.java b/src/main/java/edu/ntnu/idatt2003/ChaosGame.java
new file mode 100644
index 0000000..cfcfee5
--- /dev/null
+++ b/src/main/java/edu/ntnu/idatt2003/ChaosGame.java
@@ -0,0 +1,46 @@
+package edu.ntnu.idatt2003;
+
+import java.util.Random;
+
+/**
+ * Represents a chaos game.
+ */
+public class ChaosGame {
+    private final ChaosCanvas canvas;
+    private final ChaosGameDescription description;
+    private Vector2D currentPoint = new Vector2D(0.0 , 0.0);
+    private final Random random = new Random();
+
+    /**
+     * Creates a new ChaosGame with the given description, width, and height.
+     * @param description the description
+     * @param width the width
+     * @param height the height
+     */
+    public ChaosGame(ChaosGameDescription description, int width, int height) {
+        this.description = description;
+        this.canvas = new ChaosCanvas(width, height, description.getMinCoords(), description.getMaxCoords());
+    }
+
+
+    /**
+     * Returns the canvas of this chaos game.
+     * @return the canvas
+     */
+    public ChaosCanvas getCanvas() {
+        return canvas;
+    }
+
+    /**
+     * Runs the chaos game for the given number of steps.
+     * @param steps the number of steps
+     */
+    public void runSteps (int steps) {
+        for (int i = 0; i < steps; i++) {
+            int index = random.nextInt(description.getTransforms().size());
+            Transform2D transform = description.getTransforms().get(index);
+            currentPoint = transform.transform(currentPoint);
+            canvas.putPixel(currentPoint);
+        }
+    }
+}
-- 
GitLab


From e4d08cd87db90cf19c6bd23ee9ebb77545f78116 Mon Sep 17 00:00:00 2001
From: stevenha <steveha@stud.ntnu.no>
Date: Wed, 13 Mar 2024 15:59:57 +0100
Subject: [PATCH 2/2] Added JavaDocs to ChaosCanvas class

---
 .../java/edu/ntnu/idatt2003/ChaosCanvas.java  | 36 ++++++++++++++-----
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/src/main/java/edu/ntnu/idatt2003/ChaosCanvas.java b/src/main/java/edu/ntnu/idatt2003/ChaosCanvas.java
index fe72ddf..bf6902c 100644
--- a/src/main/java/edu/ntnu/idatt2003/ChaosCanvas.java
+++ b/src/main/java/edu/ntnu/idatt2003/ChaosCanvas.java
@@ -1,6 +1,8 @@
 package edu.ntnu.idatt2003;
 
-
+/**
+ * Represents a canvas for drawing points in 2D space.
+ */
 public class ChaosCanvas {
   private final int width;
   private final int height;
@@ -9,8 +11,14 @@ public class ChaosCanvas {
   private final Vector2D maxCoords;
   private final AffineTransform2D transformCoordsToIndices;
 
-
-
+  /**
+   * Creates a new ChaosCanvas with the given width, height, and coordinate bounds.
+   * The coordinate bounds are used to transform coordinates to indices in the canvas.
+   * @param width the width of the canvas
+   * @param height the height of the canvas
+   * @param minCoords the minimum coordinates
+   * @param maxCoords the maximum coordinates
+   */
   public ChaosCanvas(int width, int height, Vector2D minCoords, Vector2D maxCoords) {
     this.width = width;
     this.height = height;
@@ -22,7 +30,11 @@ public class ChaosCanvas {
     this.canvas = new int[height][width];
   }
 
-
+  /**
+   * Returns the width of this canvas.
+   * @param point the point to transform
+   * @return the width
+   */
   public int getPixel(Vector2D point) {
     Vector2D indices = transformCoordsToIndices.transform(point);
     int x0 = (int) indices.getX0();
@@ -30,7 +42,10 @@ public class ChaosCanvas {
     return canvas[x0][x1];
   }
 
-
+  /**
+   * Puts a pixel at the given point.
+   * @param point the point to transform
+   */
   public void putPixel(Vector2D point) {
     Vector2D indices = transformCoordsToIndices.transform(point);
     int x0 = (int) indices.getX0();
@@ -38,12 +53,17 @@ public class ChaosCanvas {
     canvas[x0][x1] = 1;
   }
 
-
+  /**
+   * Returns the canvas as a 2D array.
+   * @return the canvas
+   */
   public int[][] getCanvasArray() {
     return canvas;
   }
 
-
+  /**
+   * Clears the canvas.
+   */
   public void clear() {
     for (int i = 0; i < height; i++) {
       for (int j = 0; j < width; j++) {
@@ -51,6 +71,4 @@ public class ChaosCanvas {
       }
     }
   }
-
-
 }
\ No newline at end of file
-- 
GitLab