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

Preparing to pull.

parent 73cc408e
No related branches found
No related tags found
No related merge requests found
......@@ -171,11 +171,6 @@ public class ChaosGame {
for (int i = 0; i < n; i++) {
int j = this.random.nextInt( this.numOfTransforms);
//System.out.println(j);
//System.out.println(this.description.getTransforms().size());
//System.out.println("Before transform: " + currentPoint.getX0() + " " + currentPoint.getX1());
Vector2D newPoint = this.description.getTransforms().get(j).transform(currentPoint);
this.currentPoint = this.findValidPoint(newPoint);
......@@ -185,14 +180,13 @@ public class ChaosGame {
}
/**
* If the point is out of bounds, iterate until it is within bounds. Used
* if the useColor boolean is set to false.
* If the point is out of bounds, iterate until it is within bounds.
*
* @param point the starting point.
* @return the resulting valid point within bounds.
*/
public Vector2D findValidPoint(Vector2D point) {
if (!this.canvas.isPointInCanvasRange(point) || this.canvas.getPixel(point) == 1) {
if (!this.canvas.isPointInCanvasRange(point)) {
while (!this.canvas.isPointInCanvasRange(point)) {
int j = this.random.nextInt(this.numOfTransforms);
System.out.println("Before transform: " + point.getX0() + " " + point.getX1()); // Test
......
......@@ -71,10 +71,10 @@ public class ChaosCanvas {
// Convert the coordinates to indices in the canvas
this.transformCoordsToIndices = new AffineTransform2D(
new Matrix2x2(0, (height-1) / (minCoords.getX1() - maxCoords.getX1()),
(width-1) / (maxCoords.getX0() - minCoords.getX0()), 0),
new Vector2D(((height-1)* maxCoords.getX1()) / (maxCoords.getX1() - minCoords.getX1()),
(width-1)* minCoords.getX0() / (minCoords.getX0() - maxCoords.getX0())));
new Matrix2x2(0, (height-1) / (minCoords.getX1() - maxCoords.getX1()),
(width-1) / (maxCoords.getX0() - minCoords.getX0()), 0),
new Vector2D(((height-1)* maxCoords.getX1()) / (maxCoords.getX1() - minCoords.getX1()),
(width-1)* minCoords.getX0() / (minCoords.getX0() - maxCoords.getX0())));
}
/**
......
......@@ -23,8 +23,8 @@ public class JuliaTransform extends Transform2D {
* @param sign An integer which determines if c1 is added or subtracted in the transformation.
*/
public JuliaTransform(Complex point,int sign) {
this.c1 = point;
this.sign = sign;
this.c1 = point;
this.sign = sign;
}
......@@ -37,31 +37,28 @@ public class JuliaTransform extends Transform2D {
* @return The transformed point, represented by a vector {@link Vector2D}
*/
public Vector2D transform(Vector2D point){
if (point == null) {
throw new IllegalArgumentException("Point should not be null");
}
Vector2D temp1;
if (point == null) {
throw new IllegalArgumentException("Point should not be null");
}
Vector2D temp1;
if (sign > 0){
if (sign > 0){
temp1 = point.subtract(c1);
return new Complex(temp1.getX0(), temp1.getX1()).sqrt();
}
else if (sign < 0){
temp1 = point.subtract(c1);
Complex sqrtResult = new Complex(temp1.getX0(), temp1.getX1()).sqrt();
return sqrtResult;
}
else if (sign < 0){
temp1 = point.subtract(c1);
Complex sqrtResult = new Complex(temp1.getX0(), temp1.getX1()).sqrt();
sqrtResult = new Complex(-sqrtResult.getX0(),-sqrtResult.getX1());
return sqrtResult;
} else {
// Maybe replace with logger based on SolarLint
System.out.println("Sign is zero. No transformation performed");
return new Complex(point.getX0(),point.getX1());
}
//Complex sqrtResult = new Complex(temp1.getX0(), temp1.getX1()).sqrt();
//System.out.println("Input to sqrt: " + temp1.getX0() + temp1.getX1() + ", Output: " + sqrtResult.getX0() + sqrtResult.getX1()); // Debug line
Complex sqrtResult = new Complex(temp1.getX0(), temp1.getX1()).sqrt();
sqrtResult = new Complex(-sqrtResult.getX0(),-sqrtResult.getX1());
return sqrtResult;
} else {
// Maybe replace with logger based on SolarLint
System.out.println("Sign is zero. No transformation performed");
return new Complex(point.getX0(),point.getX1());
}
//Complex sqrtResult = new Complex(temp1.getX0(), temp1.getX1()).sqrt();
//System.out.println("Input to sqrt: " + temp1.getX0() + temp1.getX1() + ", Output: " + sqrtResult.getX0() + sqrtResult.getX1()); // Debug line
}
......
......@@ -50,7 +50,7 @@ public class ChaosGameImageView extends ImageView {
* @param controller the GUI which controls this image view.
*/
public ChaosGameImageView(ChaosGameGui controller) {
this.setOnScroll(this::userZoom);
this.setOnScroll(this::affineZoom);
this.setOnMousePressed(this::mousePressed);
this.setOnMouseDragged(this::mouseDragged);
//this.setOnMouseReleased(this::mouseReleased);
......@@ -74,7 +74,7 @@ public class ChaosGameImageView extends ImageView {
*
* @param event the event.
*/
private synchronized void userZoom(ScrollEvent event) {
private synchronized void affineZoom(ScrollEvent event) {
double newZoomFactor = event.getDeltaY() > 0 ? 1.05 : 1 / 1.05;
try {
// Get the old values
......
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