Class ChaosCanvas

java.lang.Object
edu.ntnu.stud.chaosgame.model.game.ChaosCanvas

public class ChaosCanvas extends Object
Class representing the canvas for the display of the chaos game.
  • Field Details

    • canvas

      private final int[][] canvas
      Table representing the canvas.
    • canvasIntensityArray

      private final int[][] canvasIntensityArray
      This array keeps track of how many times a pixel has been visited, to be used to determine the color of the pixel when displayed.
    • width

      private final int width
      Width of the canvas.
    • height

      private final int height
      Height of the canvas.
    • minCoords

      private final Vector2D minCoords
      The minimum coordinates of the canvas.
    • maxCoords

      private final Vector2D maxCoords
      The maximum coordinates of the canvas.
    • transformCoordsToIndices

      private final AffineTransform2D transformCoordsToIndices
      Affine transformation for converting coordinates to canvas indices.
  • Constructor Details

    • ChaosCanvas

      public ChaosCanvas(int width, int height, Vector2D minCoords, Vector2D maxCoords)
      Parameterized constructor for the class.
      Parameters:
      width - width of the canvas
      height - height of the canvas
      minCoords - minimum coordinates of the canvas
      maxCoords - maximum coordinates of the canvas
  • Method Details

    • putPixel

      public void putPixel(Vector2D point)
      Place a pixel on the canvas. If the pixel is out of bounds, it is ignored.
      Parameters:
      point - the point where the pixel is to be placed.
    • getSize

      public int[] getSize()
      Get the width and height of the canvas in the form of an array where the first index stores the width and the second stores the height.
      Returns:
      an array of two numbers containing both the width and height.
    • getMinCoords

      public Vector2D getMinCoords()
      Get the vector storing the minimum coordinates.
      Returns:
      the vector.
    • getMaxCoords

      public Vector2D getMaxCoords()
      Get the vector storing the maximum coordinates.
      Returns:
      the vector.
    • getPixel

      public int getPixel(Vector2D point)
      Get a pixel located at a point.
      Parameters:
      point - point at which the pixel is located
      Returns:
      the pixel
    • getIntensityPixel

      public int getIntensityPixel(Vector2D point)
      Get the intensity of a pixel located at a point.
      Parameters:
      point - the point to check for.
      Returns:
      the intensity at the point.
    • getCanvasIntensityArray

      public int[][] getCanvasIntensityArray()
      Get the canvas intensity array.
      Returns:
      the canvas intensity array.
    • clearCanvas

      public void clearCanvas()
      Clear the canvas of all content.
    • getCanvasArray

      public int[][] getCanvasArray()
      Get the array defining the size of the canvas.
      Returns:
      the array.
    • isPointInCanvasRange

      public boolean isPointInCanvasRange(Vector2D point)
      Checks whether a given point is within the current subsection of the coordinate space.
      Parameters:
      point - the point to check
      Returns:
      true if the point is within the subsection, false otherwise
    • getWidth

      public int getWidth()
      Get the width of the ChaosCanvas.
      Returns:
      the width of the ChaosCanvas.
    • getHeight

      public int getHeight()
      Get the height of the ChaosCanvas.
      Returns:
      the height of the ChaosCanvas.