Skip to content
Snippets Groups Projects
Commit 1f7b9ca9 authored by Edvard Granheim Harbo's avatar Edvard Granheim Harbo
Browse files

Merge branch 'task.2.2' into 'dev'

Docs: Added javadoc to ChaosCanvas class

See merge request !8
parents f4fc190d b7ebfb24
No related branches found
No related tags found
3 merge requests!54Final release,!17Part 2,!8Docs: Added javadoc to ChaosCanvas class
...@@ -3,14 +3,38 @@ package edu.ntnu.idatt2003.mappevurderingprog2.models.chaos; ...@@ -3,14 +3,38 @@ package edu.ntnu.idatt2003.mappevurderingprog2.models.chaos;
import edu.ntnu.idatt2003.mappevurderingprog2.models.AffineTransform2D; import edu.ntnu.idatt2003.mappevurderingprog2.models.AffineTransform2D;
import edu.ntnu.idatt2003.mappevurderingprog2.models.Vector2D; 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{ public class ChaosCanvas{
//The canvas is represented as a 2D array of integers, where each integer represents a color.
private int [][] canvas; private int [][] canvas;
// The width of the canvas
private int width; private int width;
// The height of the canvas
private int height; private int height;
// The minimum coordinates of the canvas
private Vector2D minCoords; private Vector2D minCoords;
// The maximum coordinates of the canvas
private Vector2D maxCoords; private Vector2D maxCoords;
// The transformation from coordinates to indices
private AffineTransform2D transformCoordsToIndices; 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) { public ChaosCanvas(int width, int height, Vector2D minCoords, Vector2D maxCoords) {
this.width = width; this.width = width;
this.height = height; this.height = height;
...@@ -19,6 +43,12 @@ public class ChaosCanvas{ ...@@ -19,6 +43,12 @@ public class ChaosCanvas{
this.canvas = new int[width][height]; 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){ public int getPixel(Vector2D point){
Vector2D indices = transformCoordsToIndices.transform(point); Vector2D indices = transformCoordsToIndices.transform(point);
int x = (int) indices.getX0(); int x = (int) indices.getX0();
...@@ -26,6 +56,13 @@ public class ChaosCanvas{ ...@@ -26,6 +56,13 @@ public class ChaosCanvas{
return canvas[x][y]; 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){ public int usePixel(Vector2D point, int color){
Vector2D indices = transformCoordsToIndices.transform(point); Vector2D indices = transformCoordsToIndices.transform(point);
int x = (int) indices.getX0(); int x = (int) indices.getX0();
...@@ -34,10 +71,18 @@ public class ChaosCanvas{ ...@@ -34,10 +71,18 @@ public class ChaosCanvas{
return canvas[x][y]; return canvas[x][y];
} }
/**
* Gets the canvas.
* @return the canvas
*/
public int[][] getCanvas(){ public int[][] getCanvas(){
return canvas; return canvas;
} }
/**
* Clears the canvas.
*/
public void clear(){ public void clear(){
for(int i = 0; i < canvas.length; i++){ for(int i = 0; i < canvas.length; i++){
for(int j = 0; j < canvas[i].length; j++){ for(int j = 0; j < canvas[i].length; j++){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment