diff --git a/src/main/java/edu/ntnu/idatt2003/controller/ButtonController.java b/src/main/java/edu/ntnu/idatt2003/controller/ButtonController.java new file mode 100644 index 0000000000000000000000000000000000000000..cebf233630d560727218ef4cecaa7d2f36eb7ff9 --- /dev/null +++ b/src/main/java/edu/ntnu/idatt2003/controller/ButtonController.java @@ -0,0 +1,39 @@ +package edu.ntnu.idatt2003.controller; + +import edu.ntnu.idatt2003.view.scenes.StartScene; +import javafx.scene.control.Button; + +public class ButtonController { + private StartScene startScene; + + public ButtonController(StartScene startScene) { + this.startScene = startScene; + } + + public void initialize() { + setButtonHandlers(); + } + + private void setButtonHandlers() { + Button btnAdd10 = startScene.getBtnAdd10(); + btnAdd10.setOnAction(e -> { + System.out.println("Add 10"); + }); + + // Set handlers for other buttons if needed + Button btnAdd100 = startScene.getBtnAdd100(); + btnAdd100.setOnAction(e -> { + System.out.println("Add 100"); + }); + + Button btnAdd1000 = startScene.getBtnAdd1000(); + btnAdd1000.setOnAction(e -> { + System.out.println("Add 1000"); + }); + + Button btnReset = startScene.getBtnReset(); + btnReset.setOnAction(e -> { + System.out.println("Reset"); + }); + } +} diff --git a/src/main/java/edu/ntnu/idatt2003/model/ChaosCanvas.java b/src/main/java/edu/ntnu/idatt2003/model/ChaosCanvas.java index 6f901d102f4448d300e394a47b88e4eeec046297..82ff3a63128f53ed85a1659d90cd4d3f831e33cc 100644 --- a/src/main/java/edu/ntnu/idatt2003/model/ChaosCanvas.java +++ b/src/main/java/edu/ntnu/idatt2003/model/ChaosCanvas.java @@ -29,6 +29,14 @@ public ChaosCanvas(int width, int height, Vector2D minCoords, Vector2D maxCoords initializeTransform(); } + public int getHeight() { + return height; + } + + public int getWidth() { + return width; + } + /** * Initializes the transformation from coordinates to indices. */ diff --git a/src/main/java/edu/ntnu/idatt2003/view/App.java b/src/main/java/edu/ntnu/idatt2003/view/App.java index 94060a91098c520ea2bc1b54ae698e614deccc8a..db4c352873cff8fe502ad35fb91ce439f64f1c08 100644 --- a/src/main/java/edu/ntnu/idatt2003/view/App.java +++ b/src/main/java/edu/ntnu/idatt2003/view/App.java @@ -1,5 +1,6 @@ package edu.ntnu.idatt2003.view; +import edu.ntnu.idatt2003.controller.ButtonController; import edu.ntnu.idatt2003.view.scenes.StartScene; import javafx.application.Application; import javafx.stage.Stage; @@ -8,9 +9,14 @@ public class App extends Application { public static void main(String[] args) { launch(args); } + @Override - public void start (Stage primaryStage) { + public void start(Stage primaryStage) { StartScene startScene = new StartScene(); - startScene.start(primaryStage); + startScene.setUpStage(primaryStage); + + // Initialize the controller and set up handlers + ButtonController buttonController = new ButtonController(startScene); + buttonController.initialize(); } } diff --git a/src/main/java/edu/ntnu/idatt2003/view/scenes/StartScene.java b/src/main/java/edu/ntnu/idatt2003/view/scenes/StartScene.java index c260decacfce03382902c1f5dbb630b63b2ef642..cd6988958155e94510ada979ff0462ae5fe824f9 100644 --- a/src/main/java/edu/ntnu/idatt2003/view/scenes/StartScene.java +++ b/src/main/java/edu/ntnu/idatt2003/view/scenes/StartScene.java @@ -1,21 +1,159 @@ package edu.ntnu.idatt2003.view.scenes; +import edu.ntnu.idatt2003.model.*; +import javafx.collections.FXCollections; +import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; -import javafx.scene.layout.StackPane; +import javafx.scene.control.ComboBox; +import javafx.scene.image.ImageView; +import javafx.scene.image.PixelWriter; +import javafx.scene.image.WritableImage; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Pane; +import javafx.scene.paint.Color; import javafx.stage.Stage; +import java.util.List; + public class StartScene { - public void start(Stage primaryStage) { + private Button btnAdd10; + private Button btnAdd100; + private Button btnAdd1000; + private Button btnReset; + + private ComboBox<String> comboBoxFractal; + private ComboBox<String> comboBoxColor; + private Button btnChangeStartVector; + private Scene scene; + //private ChaosCanvas chaosCanvas; + private WritableImage writableImage; + private ImageView imageView; + private ChaosCanvas chaosCanvas; + + public StartScene() { + initializeComponents(); + drawFractal(); + } + + private void initializeComponents() { + // Creating the root pane and setting its size + BorderPane root = new BorderPane(); + + // HBox for buttons + HBox buttonBox = new HBox(50); // spacing between buttons + HBox topBox = new HBox(50); // spacing between buttons + + buttonBox.getStyleClass().add("button-box"); + topBox.getStyleClass().add("top-box"); + + // Initialize buttons + btnAdd10 = new Button("Add 10"); + btnAdd100 = new Button("Add 100"); + btnAdd1000 = new Button("Add 1000"); + btnReset = new Button("Reset"); + btnChangeStartVector = new Button("Change start vector"); - Button startButton = new Button("Start Game"); - StackPane root = new StackPane(); - root.getChildren().add(startButton); + comboBoxFractal = new ComboBox<>(); + comboBoxFractal.setItems(FXCollections.observableArrayList( + "Option 1", "Option 2", "Option 3" + )); + comboBoxFractal.setPromptText("Choose a fractal"); - Scene scene = new Scene(root, 1300, 500); + comboBoxColor = new ComboBox<>(); + comboBoxColor.setItems(FXCollections.observableArrayList( + "Blue", "Green", "Red" + )); + comboBoxColor.setPromptText("Choose a color"); + // Add buttons to the HBox + buttonBox.getChildren().addAll(btnAdd10, btnAdd100, btnAdd1000, btnReset, btnChangeStartVector); + buttonBox.setPadding(new Insets(0, 0, 50, 50)); + + topBox.getChildren().addAll(comboBoxFractal, comboBoxColor); + topBox.setPadding(new Insets(20, 0, 0, 50)); + + // Aligning the HBox at the bottom + root.setBottom(buttonBox); + root.setTop(topBox); + + // Create a scene with the root and set the CSS style + scene = new Scene(root, 800, 600); + scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm()); + + // Initialize the ChaosCanvas and the WritableImage + chaosCanvas = new ChaosCanvas(600, 400, new Vector2D(0, 0), new Vector2D(600, 400)); + writableImage = new WritableImage(600, 400); + imageView = new ImageView(writableImage); + root.setCenter(imageView); + } + + public void setUpStage(Stage primaryStage) { + primaryStage.setTitle("ChaosGame"); primaryStage.setScene(scene); - primaryStage.setTitle("Chaos Game"); primaryStage.show(); } + + public Button getBtnAdd10() { + return btnAdd10; + } + + // Getters for other buttons if needed + public Button getBtnAdd100() { + return btnAdd100; + } + + public Button getBtnAdd1000() { + return btnAdd1000; + } + + public Button getBtnReset() { + return btnReset; + } + + private void drawFractal() { + // Clear the ChaosCanvas + chaosCanvas.clear(); + + List<Transform2D> transforms = List.of( + new AffineTransform2D(new Matrix2x2(0.5, 0, 0, 0.5), new Vector2D(0, 0)), + new AffineTransform2D(new Matrix2x2(0.5, 0, 0, 0.5), new Vector2D(300, 0)), + new AffineTransform2D(new Matrix2x2(0.5, 0, 0, 0.5), new Vector2D(150, 200)) + ); + ChaosGameDescription description = new ChaosGameDescription(transforms, new Vector2D(0, 0), new Vector2D(600, 400)); + ChaosGame chaosGame = new ChaosGame(description, 600, 400); + chaosGame.runSteps(1000); + + // Draw the fractal + // This is just a placeholder. Replace this with your fractal drawing code. + chaosCanvas.putPixel(new Vector2D(1, 1)); + chaosCanvas.putPixel(new Vector2D(1, 2)); + chaosCanvas.putPixel(new Vector2D(100, 200)); + chaosCanvas.putPixel(new Vector2D(200, 200)); + chaosCanvas.putPixel(new Vector2D(200, 300)); + chaosCanvas.putPixel(new Vector2D(200, 400)); + chaosCanvas.putPixel(new Vector2D(200, 350)); + chaosCanvas.putPixel(new Vector2D(200, 330)); + chaosCanvas.putPixel(new Vector2D(200, 320)); + chaosCanvas.putPixel(new Vector2D(200, 310)); + chaosCanvas.putPixel(new Vector2D(200, 300)); + chaosCanvas.putPixel(new Vector2D(200, 290)); + chaosCanvas.putPixel(new Vector2D(200, 280)); + + // Update the WritableImage + updateImage(); + } + + private void updateImage() { + PixelWriter pixelWriter = writableImage.getPixelWriter(); + int[][] canvasArray = chaosCanvas.getCanvasArray(); + for (int y = 0; y < chaosCanvas.getHeight(); y++) { + for (int x = 0; x < chaosCanvas.getWidth(); x++) { + int pixel = canvasArray[y][x]; + Color color = pixel == 1 ? Color.BLACK : Color.WHITE; + pixelWriter.setColor(x, y, color); + } + } + } } diff --git a/src/main/resources/style.css b/src/main/resources/style.css new file mode 100644 index 0000000000000000000000000000000000000000..e4cb20ef3620fc79eea9d0daa8f576c58af98441 --- /dev/null +++ b/src/main/resources/style.css @@ -0,0 +1,38 @@ +.button { + -fx-background-color: #bfbfbf; + -fx-border: none; + -fx-color: white; + -fx-text-decoration: none; + -fx-display: inline-block; + -fx-font-size: 16px; + -fx-margin: 4px 2px; + -fx-cursor: pointer; + -fx-transition-duration: 0.4s; /* Transition effect */ + -fx-text-align: center; + -fx-border-radius: 10px; +} + +.button:hover { + -fx-background-color: #96fa7d; + -fx-cursor: hand; +} + + +.combo-box { + -fx-background-color: #bfbfbf; + -fx-border: none; + -fx-color: white; + -fx-font-size: 16px; + -fx-cursor: pointer; + -fx-text-align: center; + -fx-border-radius: 10px; +} + +.combo-box .list-cell { + -fx-background-color: white; + -fx-text-fill: black; +} + +.combo-box:hover { + -fx-background-color: #96fa7d; +}