diff --git a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java index a844fedfd5f2812c6dec46bcad2daea97d94ae47..a4d26477c1ed0f8990dcee0e0be755c53f2965e0 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java @@ -8,6 +8,8 @@ import edu.ntnu.stud.chaosgame.model.generators.ChaosGameDescriptionFactory; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.scene.Scene; +import javafx.scene.control.ToggleGroup; +import javafx.scene.control.RadioButton; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.image.PixelWriter; @@ -34,6 +36,7 @@ public class ChaosGameGUIView { private final Timeline timeline; + public ChaosGameGUIView(Stage primaryStage) throws IOException { this.timeline = new Timeline(new KeyFrame(Duration.seconds(0.05), event -> this.drawChaosGame())); @@ -50,6 +53,14 @@ public class ChaosGameGUIView { VBox sideMenu = new VBox(); + + //TEMPORARY CODE to test Chaos Games in GUI + + ChaosGameDescriptionFactory factory = new ChaosGameDescriptionFactory(); + ChaosGameDescription description = factory.getDescriptions().get(1); + ChaosCanvas canvas = new ChaosCanvas(1000, 1000, description.getMinCoords(), description.getMaxCoords()); + game = new ChaosGame(description, canvas); + Button startButton = new Button("Start"); startButton.setOnAction(event -> timeline.play()); Button stopButton = new Button("Stop"); @@ -62,6 +73,7 @@ public class ChaosGameGUIView { WritableImage newWritableImage = new WritableImage(width, height); setPixelWriter(newWritableImage.getPixelWriter()); setImageViewFromImage(newWritableImage); + canvas.clearCanvas(); }); Button clearButton = new Button("Clear"); @@ -70,8 +82,21 @@ public class ChaosGameGUIView { getImageView().setImage(null); setCurrentLine(0); }); + + + // Radio buttons for choosing fractal type + ToggleGroup group = new ToggleGroup(); + RadioButton sierpinskiRadioButton = new RadioButton("Sierpinski"); + sierpinskiRadioButton.setToggleGroup(group); + sierpinskiRadioButton.setSelected(true); + RadioButton barnsleyRadioButton = new RadioButton("Barnsley"); + barnsleyRadioButton.setToggleGroup(group); + RadioButton juliaRadioButton = new RadioButton("Julia"); + juliaRadioButton.setToggleGroup(group); sideMenu.getChildren().addAll(startButton,stopButton,newButton,clearButton); + sideMenu.getChildren().addAll(sierpinskiRadioButton, barnsleyRadioButton, juliaRadioButton); + BorderPane borderPane = new BorderPane(); borderPane.setCenter(imageView); @@ -83,20 +108,16 @@ public class ChaosGameGUIView { primaryStage.setScene(scene); primaryStage.show(); - //TEMPORARY CODE to test Chaos Games in GUI - ChaosGameDescriptionFactory factory = new ChaosGameDescriptionFactory(); - ChaosGameDescription description = factory.getDescriptions().get(0); - ChaosCanvas canvas = new ChaosCanvas(1000, 1000, description.getMinCoords(), description.getMaxCoords()); - game = new ChaosGame(description, canvas); } public void drawChaosGame(){ - ChaosCanvas canvas = game.getCanvas(); - game.runSteps(100000); + + + game.runSteps(10); // Test implementation for drawing fractals int[][] betaArray = canvas.getCanvasArray();