Skip to content
Snippets Groups Projects
Commit cad88c47 authored by Håvard Daleng's avatar Håvard Daleng
Browse files

Resolved merge conflicts.

parent f7e8dd5c
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@ public class ChaosCanvas {
*/
private final int height;
/**
* The minimum coordinates of the canvas.
*/
......@@ -54,7 +55,7 @@ public class ChaosCanvas {
this.minCoords = minCoords;
this.maxCoords = maxCoords;
this.canvas = new int[height][width];
this.canvas = new int[width][height];
// Convert the coordinates to indices in the canvas
this.transformCoordsToIndices = new AffineTransform2D(
......@@ -81,11 +82,9 @@ public class ChaosCanvas {
* @param point the point where the pixel is to be placed.
*/
public void putPixel(Vector2D point) {
int xOffset = (int) Math.abs(minCoords.getX0());
int yOffset = (int) Math.abs(minCoords.getX1());
int xIndex = (int) transformCoordsToIndices.transform(point).getX0() + xOffset;
int yIndex = (int) transformCoordsToIndices.transform(point).getX1() + yOffset;
int xIndex = (int) transformCoordsToIndices.transform(point).getX0();
int yIndex = (int) transformCoordsToIndices.transform(point).getX1();
if (xIndex >= 0 && xIndex < width && yIndex >= 0 && yIndex < height) {
canvas[xIndex][yIndex] = 1;
......
......@@ -4,6 +4,7 @@ import edu.ntnu.stud.chaosgame.model.data.Vector2D;
import edu.ntnu.stud.chaosgame.view.ChaosGameObserver;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;
/**
......@@ -120,15 +121,41 @@ public class ChaosGame {
* @param n the number of iterations.
*/
public void runSteps(int n) {
ArrayList<Integer> results = new ArrayList<>(
Collections.nCopies(this.description.getTransforms().size(), 0));
// Testing the RNG
for (int i = 0; i < n; i++) {
int j = this.random.nextInt( this.numOfTransforms);
switch (j) {
case 0:
results.set(0, results.get(0) + 1);
break;
case 1:
results.set(1, results.get(1) + 1);
break;
case 2:
results.set(2, results.get(2) + 1);
break;
case 3:
results.set(3, results.get(3) + 1);
break;
}
//System.out.println(j);
//System.out.println(this.description.getTransforms().size());
//System.out.println("Before transform: " + currentPoint.getX0() + " " + currentPoint.getX1());
this.currentPoint = this.description.getTransforms().get(j).transform(currentPoint);
//System.out.println("After transform: " + currentPoint.getX0() + " " + currentPoint.getX1());
this.canvas.putPixel(currentPoint);
}
//this.canvas.printCanvas();
for (int i = 0; i < results.size(); i++) {
System.out.println("Transform " + i + " was chosen " + results.get(i) + " times.");
}
}
}
......@@ -16,7 +16,7 @@ public interface ChaosGameObserver {
*
* @param canvas the canvas.
*/
//void updateCanvas(ChaosCanvas canvas);
//void updateCanvas(Chaosanvas canvas);
/**
* Perform update of the ChaosGameDescription.
......
......@@ -4,4 +4,4 @@ Affine2D # Type of transform
0, 0, 0, .16, 0, 0 # transforms
.85, .04, -.04, .85, 0, 1.6
.2, -.26, .23, .22, 0, 1.6
-.15, .28, .26, .24, 0, .44
\ No newline at end of file
-.15, .28, .26, .24, 0, .44
Affine2D
0.0, 0.0
1.0, 1.0
0.5, 0.0, 0.0, 0.5, 0.0, 0.0
0.5, 0.0, 0.0, 0.5, 0.25, 0.5
0.5, 0.0, 0.0, 0.5, 0.5, 0.0
-2.65, 0
2.65, 10
0, 0, 0, .16, 0, 0
.85, .04, -.04, .85, 0, 1.6
.2, -.26, .23, .22, 0, 1.6
-.15, .28, .26, .24, 0, .44
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment