diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameButtonController.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameButtonController.java deleted file mode 100644 index f34f7afcacb664f4bd1d72ddf4395068d51e65ed..0000000000000000000000000000000000000000 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameButtonController.java +++ /dev/null @@ -1,31 +0,0 @@ -package edu.ntnu.stud.chaosgame.controller; -import edu.ntnu.stud.chaosgame.view.ChaosGameGUIView; -import javafx.animation.KeyFrame; -import javafx.animation.Timeline; -import javafx.scene.control.Button; -import javafx.scene.image.WritableImage; -import javafx.util.Duration; -import javafx.animation.Animation; - -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.05), event -> view.drawChaosGame())); - this.timeline.setCycleCount(Timeline.INDEFINITE); - startButton.setOnAction(event -> timeline.play()); - stopButton.setOnAction(event -> timeline.stop()); - newButton.setOnAction(event ->{ - WritableImage newWritableImage = new WritableImage(view.getWidth(), view.getHeight()); - view.setPixelWriter(newWritableImage.getPixelWriter()); - view.setImageViewFromImage(newWritableImage); - }); - clearButton.setOnAction(event -> { - view.getImageView().setImage(null); - view.setCurrentLine(0); - }); - - - } - -} diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosCanvas.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosCanvas.java index 6cb462f21eb64e5d635c778e831e724f776dde4e..9ccecd2da8c9c3ed8406e0dc37e87a71ef44ddc4 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosCanvas.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosCanvas.java @@ -91,9 +91,11 @@ public class ChaosCanvas { int yIndex = (int) transformCoordsToIndices.transform(point).getX1() + yOffset; if (xIndex >= 0 && xIndex < width && yIndex >= 0 && yIndex < height) { - canvas[xIndex][yIndex] = 1; + canvas[xIndex][yIndex] = 1; + } else { + System.out.println("Index out of bounds: " + xIndex + ", " + yIndex); } - } +} /** * Get the canvas array. diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameFileHandler.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameFileHandler.java index 8af2091c7366daf24d1de20a1ad8b6d8c211627f..6fd85795c43fc1a8834fbf9b15019edefe5f8dfb 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameFileHandler.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameFileHandler.java @@ -33,8 +33,8 @@ public class ChaosGameFileHandler { try (Scanner scanner = new Scanner(Files.newInputStream(paths))) { scanner.useLocale(Locale.ENGLISH); - // Use a delimiter that splits on commas and new lines, and ignores comment lines. -scanner.useDelimiter(",\\s*|\\r?\\n|(\\s*#.*\\s*)"); + // Use a delimiter that splits on commas and new lines, and ignores # comments + scanner.useDelimiter(",\\s*|\\r?\\n|(\\s*#.*\\s*)"); String firstLine = scanner.next().trim(); 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 91b7b6a8bda0f468dff183bf7f23fb512d8b9e35..a844fedfd5f2812c6dec46bcad2daea97d94ae47 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java @@ -1,11 +1,12 @@ package edu.ntnu.stud.chaosgame.view; -import edu.ntnu.stud.chaosgame.controller.ChaosGameButtonController; import edu.ntnu.stud.chaosgame.controller.game.ChaosCanvas; import edu.ntnu.stud.chaosgame.controller.game.ChaosGame; import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription; import edu.ntnu.stud.chaosgame.model.generators.ChaosGameDescriptionFactory; +import javafx.animation.KeyFrame; +import javafx.animation.Timeline; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; @@ -16,6 +17,7 @@ import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.control.Button; +import javafx.util.Duration; import java.io.IOException; @@ -29,9 +31,14 @@ public class ChaosGameGUIView { private int height; private ChaosGame game; + private final Timeline timeline; + public ChaosGameGUIView(Stage primaryStage) throws IOException { + this.timeline = new Timeline(new KeyFrame(Duration.seconds(0.05), event -> this.drawChaosGame())); + + imageView = new ImageView(); width = 1100; height = 1000; @@ -44,10 +51,25 @@ public class ChaosGameGUIView { VBox sideMenu = new VBox(); Button startButton = new Button("Start"); + startButton.setOnAction(event -> timeline.play()); Button stopButton = new Button("Stop"); + stopButton.setOnAction(event -> timeline.stop()); + + Button newButton = new Button("New"); + + newButton.setOnAction(event ->{ + WritableImage newWritableImage = new WritableImage(width, height); + setPixelWriter(newWritableImage.getPixelWriter()); + setImageViewFromImage(newWritableImage); + }); + Button clearButton = new Button("Clear"); - ChaosGameButtonController chaosGameButtonController = new ChaosGameButtonController(this,startButton,stopButton,newButton,clearButton); + + clearButton.setOnAction(event -> { + getImageView().setImage(null); + setCurrentLine(0); + }); sideMenu.getChildren().addAll(startButton,stopButton,newButton,clearButton); @@ -64,7 +86,7 @@ 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(0); ChaosCanvas canvas = new ChaosCanvas(1000, 1000, description.getMinCoords(), description.getMaxCoords()); game = new ChaosGame(description, canvas); @@ -74,7 +96,7 @@ public class ChaosGameGUIView { public void drawChaosGame(){ ChaosCanvas canvas = game.getCanvas(); - game.runSteps(1000); + game.runSteps(100000); // Test implementation for drawing fractals int[][] betaArray = canvas.getCanvasArray();