Skip to content
Snippets Groups Projects

Refactor: Implemented ChaosCanvas class and implemented methods for the class

Merged Tam Minh Le requested to merge task.2.2 into dev
1 file
+ 49
0
Compare changes
  • Side-by-side
  • Inline
package edu.ntnu.idatt2003.mappevurderingprog2.models.chaos;
import edu.ntnu.idatt2003.mappevurderingprog2.models.AffineTransform2D;
import edu.ntnu.idatt2003.mappevurderingprog2.models.Vector2D;
public class ChaosCanvas{
private int [][] canvas;
private int width;
private int height;
private Vector2D minCoords;
private Vector2D maxCoords;
private AffineTransform2D transformCoordsToIndices;
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];
}
public int getPixel(Vector2D point){
Vector2D indices = transformCoordsToIndices.transform(point);
int x = (int) indices.getX0();
int y = (int) indices.getX1();
return canvas[x][y];
}
public int usePixel(Vector2D point, int color){
Vector2D indices = transformCoordsToIndices.transform(point);
int x = (int) indices.getX0();
int y = (int) indices.getX1();
canvas[x][y] = color;
return canvas[x][y];
}
public int[][] getCanvas(){
return canvas;
}
public void clear(){
for(int i = 0; i < canvas.length; i++){
for(int j = 0; j < canvas[i].length; j++){
canvas[i][j] = 0;
}
}
}
}
\ No newline at end of file
Loading