Skip to content
Snippets Groups Projects
Commit 86729d84 authored by Magnus Eik's avatar Magnus Eik
Browse files

Bug fix to readFromFile,add println for bug hunting.

parent d4c109f4
No related branches found
No related tags found
No related merge requests found
......@@ -8,5 +8,6 @@
</component>
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/idatt2003" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -11,7 +11,7 @@ public class ChaosGameButtonController {
private final Timeline timeline;
public ChaosGameButtonController(ChaosGameGUIView view, Button startButton, Button stopButton, Button newButton, Button clearButton) {
this.timeline = new Timeline(new KeyFrame(Duration.seconds(0.01), event -> view.drawChaosGame(10)));
this.timeline = new Timeline(new KeyFrame(Duration.seconds(0.05), event -> view.drawChaosGame()));
this.timeline.setCycleCount(Timeline.INDEFINITE);
startButton.setOnAction(event -> timeline.play());
stopButton.setOnAction(event -> timeline.stop());
......
......@@ -60,8 +60,10 @@ public class ChaosGame {
public void runSteps(int n) {
for (int i = 0; i < n; i++) {
int j = this.random.nextInt(0, this.numOfTransforms);
//System.out.println("Before transform: " + currentPoint.getX0() + " " + currentPoint.getX1());
this.currentPoint = this.description.getTransforms().get(j).transform(currentPoint);
//System.out.println(currentPoint.getX0() + " " + currentPoint.getX1());
//System.out.println("After transform: " + currentPoint.getX0() + " " + currentPoint.getX1());
this.canvas.putPixel(currentPoint);
}
//this.canvas.printCanvas();
......
......@@ -97,11 +97,13 @@ public class ChaosGameFileHandler {
double cReal = scanner.nextDouble();
double cImag = scanner.nextDouble();
Complex complex = new Complex(cReal,cImag);
JuliaTransform juliaTransform = new JuliaTransform(complex,1);
transforms.add(juliaTransform);
JuliaTransform juliaTransform1 = new JuliaTransform(complex,1);
JuliaTransform juliaTransform2 = new JuliaTransform(complex,-1);
transforms.add(juliaTransform1);
transforms.add(juliaTransform2);
}
} else{throw new IllegalStateException("Invalid Chaos Game, expected 'Affine2D' or 'Juli'.");}
} else{throw new IllegalStateException("Invalid Chaos Game, expected 'Affine2D' or 'Julia'.");}
} catch (IOException e) {
throw new IOException("Failure to read file", e);
}
......
......@@ -51,13 +51,16 @@ public class JuliaTransform extends Transform2D {
System.out.println("Sign is zero. No transformation performed");
return new Complex(point.getX0(),point.getX1());
}
return new Complex(temp1.getX0(), temp1.getX1()).sqrt();
}
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
return sqrtResult; }
/**
* Getter method to use with {@link ChaosGameFileHandler}
* @return The complex number used in the transformation.
*/
public Complex getC1(){return this.c1;}
}
......@@ -64,17 +64,17 @@ public class ChaosGameGUIView {
//TEMPORARY CODE to test Chaos Games in GUI
ChaosGameDescriptionFactory factory = new ChaosGameDescriptionFactory();
ChaosGameDescription description = factory.getDescriptions().get(2);
ChaosGameDescription description = factory.getDescriptions().get(1);
ChaosCanvas canvas = new ChaosCanvas(1000, 1000, description.getMinCoords(), description.getMaxCoords());
game = new ChaosGame(description, canvas);
}
public void drawChaosGame(int numLines){
public void drawChaosGame(){
ChaosCanvas canvas = game.getCanvas();
game.runSteps(2000);
game.runSteps(100000);
// Test implementation for drawing fractals
int[][] betaArray = canvas.getCanvasArray();
......
Affine2D
0.0, 0.0
1.0, 1.0
0.0, 0.0, 0.0, 0.16, 0.0, 0.0
0.85, 0.04, -0.04, 0.85, 0.0, 1.6
0.2, -0.26, 0.23, 0.22, 0.0, 0.16
-0.15, 0.28, 0.26, 0.24, 0, 0.44
-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
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
Julia
-1.6, -1
1.6, 1
-.74543, .11301
\ 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