Skip to content
Snippets Groups Projects

Docs: Added javadoc to ChaosCanvas class

Merged Tam Minh Le requested to merge task.2.2 into dev
1 file
+ 45
0
Compare changes
  • Side-by-side
  • Inline
@@ -3,14 +3,38 @@ package edu.ntnu.idatt2003.mappevurderingprog2.models.chaos;
import edu.ntnu.idatt2003.mappevurderingprog2.models.AffineTransform2D;
import edu.ntnu.idatt2003.mappevurderingprog2.models.Vector2D;
/**
* The ChaosCanvas class represent a 2D canvas with the ability to store and retrieve pixels.
* The class can apply transformations to obtain pixel values from a given point.
*/
public class ChaosCanvas{
//The canvas is represented as a 2D array of integers, where each integer represents a color.
private int [][] canvas;
// The width of the canvas
private int width;
// The 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;
// The transformation from coordinates to indices
private AffineTransform2D transformCoordsToIndices;
/**
* Constructs a ChaosCanvas object with the given width, height, minimum coordinates, and maximum coordinates.
* @param width the width of the canvas
* @param height the height of the canvas
* @param minCoords the minimum coordinates of the canvas
* @param maxCoords the maximum coordinates of the canvas
*/
public ChaosCanvas(int width, int height, Vector2D minCoords, Vector2D maxCoords) {
this.width = width;
this.height = height;
@@ -19,6 +43,12 @@ public class ChaosCanvas{
this.canvas = new int[width][height];
}
/**
* Gets the color of the pixel at the given point.
* @param transformCoordsToIndices the transformation from coordinates to indices
* @return the color of the pixel at the given point
*/
public int getPixel(Vector2D point){
Vector2D indices = transformCoordsToIndices.transform(point);
int x = (int) indices.getX0();
@@ -26,6 +56,13 @@ public class ChaosCanvas{
return canvas[x][y];
}
/**
* Sets the color of the pixel at the given point.
* @param point the point to set the color of
* @param color the color to set
* @return the color of the pixel after setting
*/
public int usePixel(Vector2D point, int color){
Vector2D indices = transformCoordsToIndices.transform(point);
int x = (int) indices.getX0();
@@ -34,10 +71,18 @@ public class ChaosCanvas{
return canvas[x][y];
}
/**
* Gets the canvas.
* @return the canvas
*/
public int[][] getCanvas(){
return canvas;
}
/**
* Clears the canvas.
*/
public void clear(){
for(int i = 0; i < canvas.length; i++){
for(int j = 0; j < canvas[i].length; j++){
Loading