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

Add image size field to ChaosGameGuiView

parent 1671807b
No related branches found
No related tags found
No related merge requests found
......@@ -54,12 +54,12 @@ public class ChaosGameGuiView implements ChaosGameObserver {
private PixelWriter pixelWriter;
/**
* The ImageView for the GUI..
* The ImageView for the GUI.
*/
private ChaosGameImageView imageView;
/**
* The Scene for the GUI..
* The Scene for the GUI.
*/
private Scene scene;
......@@ -112,6 +112,9 @@ public class ChaosGameGuiView implements ChaosGameObserver {
private RadioButton juliaRadioButton;
private RadioButton improvedBarnsleyButton;
private final int resolutionHeight = 1000;
private final int resolutionWidth = 1000;
public ChaosGameGuiView(Stage primaryStage) throws IOException {
......@@ -132,6 +135,8 @@ public class ChaosGameGuiView implements ChaosGameObserver {
// Timeline
this.timeline = new Timeline(new KeyFrame(Duration.seconds(0.05), event -> this.drawChaosGame()));
this.initializeImageView();
this.timeline.setCycleCount(Timeline.INDEFINITE);
// Side menu
......@@ -185,7 +190,7 @@ public class ChaosGameGuiView implements ChaosGameObserver {
this.descriptionRef = new AtomicReference<>(factory.getDescriptions().get(0));
this.description = descriptionRef.get();
this.canvas = new ChaosCanvas(1000, 1000, descriptionRef.get().getMinCoords(), descriptionRef.get().getMaxCoords());
this.canvas = new ChaosCanvas(resolutionWidth, resolutionHeight, descriptionRef.get().getMinCoords(), descriptionRef.get().getMaxCoords());
game = new ChaosGame(this.description, canvas);
}
......@@ -195,11 +200,13 @@ public class ChaosGameGuiView implements ChaosGameObserver {
private void initializeImageView() {
// Image view
this.imageView = new ChaosGameImageView(this);
width = 1000;
height = 1000;
width = resolutionWidth;
height = resolutionHeight;
WritableImage writableImage = new WritableImage(width, height);
pixelWriter = writableImage.getPixelWriter();
this.imageView.setImage(writableImage);
this.imageView.setFitHeight(1000);
this.imageView.setFitWidth(1000);
this.fillImageView();
/*imageView.setOnScroll(event -> {
......@@ -264,54 +271,54 @@ public class ChaosGameGuiView implements ChaosGameObserver {
// Set action for Sierpinski radio button.
sierpinskiRadioButton.setOnAction(event -> {
timeline.stop();
canvasRef.get().clearCanvas();
//canvasRef.get().clearCanvas();
WritableImage newWritableImage = new WritableImage(width, height);
setPixelWriter(newWritableImage.getPixelWriter());
setImageViewFromImage(newWritableImage);
this.fillImageView();
canvas.clearCanvas();
//canvas.clearCanvas();
this.descriptionRef.set(factory.getDescriptions().get(0)); // Assuming the Sierpinski description is at index 0
canvasRef.set(new ChaosCanvas(1000, 1000, this.descriptionRef.get().getMinCoords(), this.descriptionRef.get().getMaxCoords()));
canvasRef.set(new ChaosCanvas(resolutionWidth, resolutionHeight, this.descriptionRef.get().getMinCoords(), this.descriptionRef.get().getMaxCoords()));
game = new ChaosGame(this.descriptionRef.get(), canvasRef.get());
});
// Set action for Barnsley radio button.
barnsleyRadioButton.setOnAction(event -> {
timeline.stop();
canvasRef.get().clearCanvas();
//canvasRef.get().clearCanvas();
WritableImage newWritableImage = new WritableImage(width, height);
setPixelWriter(newWritableImage.getPixelWriter());
setImageViewFromImage(newWritableImage);
this.fillImageView();
canvas.clearCanvas();
//canvas.clearCanvas();
this.descriptionRef.set(factory.getDescriptions().get(1)); // Assuming the Sierpinski description is at index 0
canvasRef.set(new ChaosCanvas(1000, 1000, this.descriptionRef.get().getMinCoords(), this.descriptionRef.get().getMaxCoords()));
canvasRef.set(new ChaosCanvas(resolutionWidth, resolutionHeight, this.descriptionRef.get().getMinCoords(), this.descriptionRef.get().getMaxCoords()));
game = new ChaosGame(this.descriptionRef.get(), canvasRef.get());
});
// Set action for Julia radio button.
juliaRadioButton.setOnAction(event -> {
timeline.stop();
canvasRef.get().clearCanvas();
//canvasRef.get().clearCanvas();
WritableImage newWritableImage = new WritableImage(width, height);
setPixelWriter(newWritableImage.getPixelWriter());
setImageViewFromImage(newWritableImage);
this.fillImageView();
canvas.clearCanvas();
//canvas.clearCanvas();
this.descriptionRef.set(factory.getDescriptions().get(2)); // Assuming the Sierpinski description is at index 0
canvasRef.set(new ChaosCanvas(1000, 1000, this.descriptionRef.get().getMinCoords(), this.descriptionRef.get().getMaxCoords()));
canvasRef.set(new ChaosCanvas(resolutionWidth, resolutionHeight, this.descriptionRef.get().getMinCoords(), this.descriptionRef.get().getMaxCoords()));
game = new ChaosGame(this.descriptionRef.get(), canvasRef.get());
});
improvedBarnsleyButton.setOnAction(event -> {
timeline.stop();
canvasRef.get().clearCanvas();
//canvasRef.get().clearCanvas();
WritableImage newWritableImage = new WritableImage(width, height);
setPixelWriter(newWritableImage.getPixelWriter());
setImageViewFromImage(newWritableImage);
this.fillImageView();
canvas.clearCanvas();
//canvas.clearCanvas();
// Test
this.descriptionRef.set(factory.getDescriptions().get(3)); // Assuming the Sierpinski description is at index 0
......@@ -327,7 +334,7 @@ public class ChaosGameGuiView implements ChaosGameObserver {
}
canvasRef.set(new ChaosCanvas(1000, 1000, this.descriptionRef.get().getMinCoords(), this.descriptionRef.get().getMaxCoords()));
canvasRef.set(new ChaosCanvas(resolutionWidth, resolutionHeight, this.descriptionRef.get().getMinCoords(), this.descriptionRef.get().getMaxCoords()));
game = new ChaosGame(this.descriptionRef.get(), canvasRef.get());
});
......@@ -398,7 +405,7 @@ public class ChaosGameGuiView implements ChaosGameObserver {
ChaosCanvas canvas = game.getCanvas();
game.runSteps(1000000);
game.runSteps(100000);
// Test implementation for drawing fractals
int[][] betaArray = canvas.getCanvasArray();
......
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