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

Merge branch 'task.2.2' into 'dev'

Refactor: Implemented ChaosCanvas class and implemented methods for the class

See merge request !7
parents b363a5b1 9dcf09df
No related branches found
No related tags found
3 merge requests!54Final release,!17Part 2,!7Refactor: Implemented ChaosCanvas class and implemented methods for the class
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment