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

Add fractal choice control to radio buttons and a quit button

parent e48ef630
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ import edu.ntnu.stud.chaosgame.model.generators.ChaosGameDescriptionFactory; ...@@ -7,6 +7,7 @@ import edu.ntnu.stud.chaosgame.model.generators.ChaosGameDescriptionFactory;
import javafx.animation.KeyFrame; import javafx.animation.KeyFrame;
import javafx.animation.Timeline; import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.ToggleGroup; import javafx.scene.control.ToggleGroup;
import javafx.scene.control.RadioButton; import javafx.scene.control.RadioButton;
...@@ -22,6 +23,7 @@ import javafx.scene.control.Button; ...@@ -22,6 +23,7 @@ import javafx.scene.control.Button;
import javafx.util.Duration; import javafx.util.Duration;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;
public class ChaosGameGUIView { public class ChaosGameGUIView {
private int currentLine = 0; private int currentLine = 0;
...@@ -43,7 +45,7 @@ public class ChaosGameGUIView { ...@@ -43,7 +45,7 @@ public class ChaosGameGUIView {
imageView = new ImageView(); imageView = new ImageView();
width = 1100; width = 1000;
height = 1000; height = 1000;
WritableImage writableImage = new WritableImage(width, height); WritableImage writableImage = new WritableImage(width, height);
...@@ -57,9 +59,9 @@ public class ChaosGameGUIView { ...@@ -57,9 +59,9 @@ public class ChaosGameGUIView {
//TEMPORARY CODE to test Chaos Games in GUI //TEMPORARY CODE to test Chaos Games in GUI
ChaosGameDescriptionFactory factory = new ChaosGameDescriptionFactory(); ChaosGameDescriptionFactory factory = new ChaosGameDescriptionFactory();
ChaosGameDescription description = factory.getDescriptions().get(1); AtomicReference<ChaosGameDescription> description = new AtomicReference<>(factory.getDescriptions().get(0));
ChaosCanvas canvas = new ChaosCanvas(1000, 1000, description.getMinCoords(), description.getMaxCoords()); ChaosCanvas canvas = new ChaosCanvas(1000, 1000, description.get().getMinCoords(), description.get().getMaxCoords());
game = new ChaosGame(description, canvas); game = new ChaosGame(description.get(), canvas);
Button startButton = new Button("Start"); Button startButton = new Button("Start");
startButton.setOnAction(event -> timeline.play()); startButton.setOnAction(event -> timeline.play());
...@@ -94,8 +96,55 @@ public class ChaosGameGUIView { ...@@ -94,8 +96,55 @@ public class ChaosGameGUIView {
RadioButton juliaRadioButton = new RadioButton("Julia"); RadioButton juliaRadioButton = new RadioButton("Julia");
juliaRadioButton.setToggleGroup(group); juliaRadioButton.setToggleGroup(group);
AtomicReference<ChaosCanvas> canvasRef = new AtomicReference<>(canvas);
sierpinskiRadioButton.setOnAction(event -> {
timeline.stop();
canvasRef.get().clearCanvas();
WritableImage newWritableImage = new WritableImage(width, height);
setPixelWriter(newWritableImage.getPixelWriter());
setImageViewFromImage(newWritableImage);
canvas.clearCanvas();
description.set(factory.getDescriptions().get(0)); // Assuming the Sierpinski description is at index 0
canvasRef.set(new ChaosCanvas(1000, 1000, description.get().getMinCoords(), description.get().getMaxCoords()));
game = new ChaosGame(description.get(), canvasRef.get());
});
barnsleyRadioButton.setOnAction(event -> {
timeline.stop();
canvasRef.get().clearCanvas();
WritableImage newWritableImage = new WritableImage(width, height);
setPixelWriter(newWritableImage.getPixelWriter());
setImageViewFromImage(newWritableImage);
canvas.clearCanvas();
description.set(factory.getDescriptions().get(1)); // Assuming the Sierpinski description is at index 0
canvasRef.set(new ChaosCanvas(1000, 1000, description.get().getMinCoords(), description.get().getMaxCoords()));
game = new ChaosGame(description.get(), canvasRef.get());
});
juliaRadioButton.setOnAction(event -> {
timeline.stop();
canvasRef.get().clearCanvas();
WritableImage newWritableImage = new WritableImage(width, height);
setPixelWriter(newWritableImage.getPixelWriter());
setImageViewFromImage(newWritableImage);
canvas.clearCanvas();
description.set(factory.getDescriptions().get(2)); // Assuming the Sierpinski description is at index 0
canvasRef.set(new ChaosCanvas(1000, 1000, description.get().getMinCoords(), description.get().getMaxCoords()));
game = new ChaosGame(description.get(), canvasRef.get());
});
// Quit button
Button quitButton = new Button("Quit");
quitButton.setOnAction(event -> Platform.exit());
// Add basic control buttons
sideMenu.getChildren().addAll(startButton,stopButton,newButton,clearButton); sideMenu.getChildren().addAll(startButton,stopButton,newButton,clearButton);
// Add fractal radio buttons
sideMenu.getChildren().addAll(sierpinskiRadioButton, barnsleyRadioButton, juliaRadioButton); sideMenu.getChildren().addAll(sierpinskiRadioButton, barnsleyRadioButton, juliaRadioButton);
// Add quit button
sideMenu.getChildren().add(quitButton);
BorderPane borderPane = new BorderPane(); BorderPane borderPane = new BorderPane();
...@@ -117,7 +166,7 @@ public class ChaosGameGUIView { ...@@ -117,7 +166,7 @@ public class ChaosGameGUIView {
ChaosCanvas canvas = game.getCanvas(); ChaosCanvas canvas = game.getCanvas();
game.runSteps(10); game.runSteps(100000);
// Test implementation for drawing fractals // Test implementation for drawing fractals
int[][] betaArray = canvas.getCanvasArray(); 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