Skip to content
Snippets Groups Projects
Commit 9dda669b authored by Johan Martin Arntsen's avatar Johan Martin Arntsen
Browse files

Resolved some confilcts in merge

parents 22fe1918 1df5714c
No related branches found
No related tags found
1 merge request!9Added and improved test classes
Showing
with 196 additions and 77 deletions
......@@ -14,7 +14,6 @@ public class SceneController {
private final MainPage mainPage;
private final JuliaPage juliaPage;
private final AffinePage affinePage;
......@@ -24,7 +23,7 @@ public class SceneController {
primaryStage.setScene(scene);
this.mainPage = new MainPage(this);
this.affinePage = new AffinePage(this);
this.juliaPage = new JuliaPage();
this.juliaPage = new JuliaPage(this);
}
public void showMainPage() {
......
......@@ -6,15 +6,9 @@ import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Vector2D minCoords = new Vector2D(0, 0);
Vector2D maxCoords = new Vector2D(1, 1);
AffineTransform2D
transform1 = new AffineTransform2D(new Matrix2x2(0.5, 0, 0, 0.5), new Vector2D(0, 0));
AffineTransform2D transform2 = new AffineTransform2D(new Matrix2x2(0.5, 0, 0, 0.5), new Vector2D(0.25, 0.5));
AffineTransform2D transform3 = new AffineTransform2D(new Matrix2x2(0.5, 0, 0, 0.5), new Vector2D(0.5, 0));
ChaosGameDescription description = new ChaosGameDescription(minCoords, maxCoords, Arrays.asList(transform1, transform2, transform3));
ChaosGameDescription description = ChaosGameDescriptionFactory.juliaSet(new Complex(-.74543, .11301));
ChaosGame chaosGame = new ChaosGame(description, 150, 150);
chaosGame.runSteps(10000000);
chaosGame.runSteps(1000000);
chaosGame.getCanvas().showASCIICanvas();
......
......@@ -21,8 +21,8 @@ public class ChaosGameDescriptionFactory {
return new ChaosGameDescription(minCoords, maxCoords, Arrays.asList(transform1, transform2, transform3, transform4));
}
public static ChaosGameDescription juliaSet(Complex c) {
Vector2D minCoords = new Vector2D(-1.5, -1.5);
Vector2D maxCoords = new Vector2D(1.5, 1.5);
Vector2D minCoords = new Vector2D(-1.6, -1);
Vector2D maxCoords = new Vector2D(1.6, 1);
JuliaTransform transform1 = new JuliaTransform(c, 1);
JuliaTransform transform2 = new JuliaTransform(c, -1);
return new ChaosGameDescription(minCoords, maxCoords, Arrays.asList(transform1, transform2));
......
......@@ -36,7 +36,7 @@ public class JuliaTransform implements Transform2D {
* The point is first subtracted by the point,
* and then the square root of the result is calculated.
*
* @param point the point to be transformed
* @param pointZ the point to be transformed
* @return the transformed point
*/
public Vector2D transform(Vector2D pointZ) {
......
......@@ -182,7 +182,7 @@ public class AffinePage {
Button juliaPageButton = new Button("Julia Transformation");
juliaPageButton.setOnAction(e ->
sceneController.showAffinePage()
sceneController.showJuliaPage()
);
affinePageButton.setAlignment(Pos.CENTER);
......
package edu.ntnu.stud.view;
import edu.ntnu.stud.controller.SceneController;
import edu.ntnu.stud.model.*;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javax.imageio.ImageWriter;
import javax.swing.border.Border;
import java.awt.*;
import java.io.FileNotFoundException;
public class JuliaPage {
private final BorderPane juliaRoot = new BorderPane();
private final StackPane juliaRoot = new StackPane();
public JuliaPage() throws FileNotFoundException {
juliaRoot.setId("julia-root");
VBox sidemenu = new VBox();
sidemenu.setSpacing(20);
sidemenu.setAlignment(Pos.CENTER_LEFT);
BorderPane juliaContent = new BorderPane();
Label title = new Label("Julia Transformation");
title.setFont(javafx.scene.text.Font.font(20));
sidemenu.getChildren().add(title);
public JuliaPage(SceneController sceneController) throws FileNotFoundException {
juliaRoot.setId("julia-root");
HBox juliaCoords = new HBox();
HBox juliaConstant = new HBox();
VBox juliaIterations = new VBox();
VBox leftMenu = getLeftMenu(sceneController);
HBox centerMenu = getCenterMenu(sceneController);
Label display = new Label("");
juliaContent.setLeft(leftMenu);
juliaContent.setCenter(centerMenu);
juliaRoot.getChildren().addAll(
juliaContent
);
StackPane.setAlignment(juliaContent, Pos.CENTER);
StackPane.setMargin(juliaContent, new Insets(20, 80, 20, 20));
TextField xMinCoord = new TextField();
xMinCoord.setMaxWidth(40);
xMinCoord.setPromptText("Min");
TextField xMaxCoord = new TextField();
xMaxCoord.setMaxWidth(40);
xMaxCoord.setPromptText("Max");
TextField yMinCoord = new TextField();
yMinCoord.setMaxWidth(40);
yMinCoord.setPromptText("Min");
TextField yMaxCoord = new TextField();
yMaxCoord.setMaxWidth(40);
yMaxCoord.setPromptText("Max");
}
public StackPane getRoot() {
return juliaRoot;
}
public VBox getLeftMenu(SceneController sceneController) {
VBox leftMenu = new VBox();
Text titleText = new Text("Julia Transformation");
titleText.setFont(Font.font("", 20));
HBox minBox = new HBox();
HBox maxBox = new HBox();
Label minLabel = new Label("Min coordinates");
TextField xMinField = new TextField();
xMinField.setPromptText("X min");
TextField yMinField = new TextField();
yMinField.setPromptText("Y min");
Label maxLabel = new Label("Max coordinates");
TextField xMaxField = new TextField();
xMaxField.setPromptText("X max");
TextField yMaxField = new TextField();
yMaxField.setPromptText("Y max");
double preferredWidth = 50;
HBox complexNumber = new HBox();
Label complexLabel = new Label("Complex number");
TextField realField = new TextField();
realField.setPromptText("Real");
TextField imaginaryField = new TextField();
imaginaryField.setPromptText("Imaginary");
Label iLabel = new Label("i");
complexNumber.getChildren().addAll(realField, imaginaryField, iLabel);
HBox iterationsBox = new HBox();
Label iterationsLabel = new Label("Iterations");
TextField iterationsField = new TextField();
iterationsBox.getChildren().add(iterationsField);
minBox.getChildren().addAll(xMinField, yMinField);
maxBox.getChildren().addAll(xMaxField, yMaxField);
Button transformButton = new Button("Transform");
// transformButton.setOnAction(e -> {
// double xMin = Double.parseDouble(xMinField.getText());
// double yMin = Double.parseDouble(yMinField.getText());
// double xMax = Double.parseDouble(xMaxField.getText());
// double yMax = Double.parseDouble(yMaxField.getText());
// double real = Double.parseDouble(realField.getText());
// double imaginary = Double.parseDouble(imaginaryField.getText());
// int iterations = Integer.parseInt(iterationsField.getText());
// sceneController.showJuliaSet(xMin, yMin, xMax, yMax, real, imaginary, iterations);
// });
transformButton.setMinSize(100, 50);
Button mainPageButton = new Button("Main Page");
Button affinePageButton = new Button("Affine Transformation");
Button juliaPageButton = new Button("Julia transformation");
mainPageButton.setOnAction(e -> sceneController.showMainPage());
affinePageButton.setOnAction(e -> sceneController.showAffinePage());
juliaPageButton.setOnAction(e -> sceneController.showJuliaPage());
leftMenu.getChildren().addAll(
mainPageButton,
affinePageButton,
juliaPageButton,
titleText,
minLabel,
minBox,
maxLabel,
maxBox,
complexLabel,
complexNumber,
iterationsLabel,
iterationsBox,
transformButton
);
TextField real = new TextField();
real.setMaxWidth(40);
real.setPromptText("Real");
TextField imagenary = new TextField();
imagenary.setMaxWidth(40);
imagenary.setPromptText("Imaginary");
leftMenu.setId("left-menu");
return leftMenu;
}
public HBox getCenterMenu(SceneController sceneController) {
HBox centerMenu = new HBox();
sidemenu.getChildren().addAll(juliaCoords, juliaConstant, juliaIterations);
juliaRoot.setLeft(sidemenu);
Canvas canvas = getCanvas();
centerMenu.getChildren().addAll(canvas);
juliaCoords.getChildren().addAll(
new Label("Coordinates:"),
new Label("X:"), xMinCoord, xMaxCoord,
new Label("Y:"), yMinCoord, yMaxCoord
);
juliaCoords.setAlignment(Pos.CENTER_LEFT);
juliaCoords.setSpacing(10);
return centerMenu;
}
public Canvas getCanvas() {
int width = 800;
int height = 800;
Canvas canvas = new Canvas(width, height);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
Complex c = new Complex(-0.74543, 0.11301);
// JuliaTransform juliaTransform = new JuliaTransform(c, 1);
// JuliaTransform juliaTransform1 = new JuliaTransform(c, -1);
//
//
//
// Vector2D point = new Vector2D(1.6, 1);
//
// Vector2D transformedPoint = juliaTransform.transform(point);
ChaosGameDescription description = ChaosGameDescriptionFactory.juliaSet(c);
ChaosGame chaosGame = new ChaosGame(description, width, height);
chaosGame.runSteps(1000000);
int[][] canvasArray = chaosGame.getCanvas().getCanvasArray();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if (canvasArray[i][j] == 1) {
gc.getPixelWriter().setColor(i, j, Color.BLACK);
}
}
}
juliaConstant.getChildren().addAll(
new Label("Constant:"),
real, imagenary, new Label("i")
);
juliaConstant.setAlignment(Pos.CENTER_LEFT);
juliaConstant.setSpacing(10);
// for (int i = 0; i < 100; i++) {
// for (int j = 0; j < 100; j++) {
// Vector2D point1 = new Vector2D(i, j);
// Vector2D transformedPoint1 = juliaTransform.transform(point1);
// gc.setFill(Color.BLACK);
// gc.fillRect(transformedPoint1.getX0(), transformedPoint1.getX1(), 1, 1);
// }
// }
juliaIterations.getChildren().addAll(
new Label("Iterations:"),
new TextField()
);
juliaIterations.setAlignment(Pos.CENTER_LEFT);
juliaIterations.setSpacing(10);
juliaRoot.setCenter(display);
}
public BorderPane getRoot() {
return juliaRoot;
return canvas;
}
}
File deleted
artifactId=ChaosGame
groupId=edu.ntnu.stud
version=1.0-SNAPSHOT
edu/ntnu/stud/launcher/ChaosGameCLI.class
edu/ntnu/stud/launcher/MainUI.class
edu/ntnu/stud/model/JuliaTransform.class
edu/ntnu/stud/model/ChaosGameDescriptionFactory.class
edu/ntnu/stud/view/JuliaPage.class
edu/ntnu/stud/model/AffineTransform2D.class
edu/ntnu/stud/model/ChaosGameFileHandler.class
edu/ntnu/stud/model/Complex.class
edu/ntnu/stud/view/MainPage.class
edu/ntnu/stud/model/Matrix2x2.class
edu/ntnu/stud/model/Transform2D.class
edu/ntnu/stud/model/ChaosCanvas.class
edu/ntnu/stud/launcher/Main.class
edu/ntnu/stud/controller/ChaosGameObserver.class
edu/ntnu/stud/model/ChaosGameDescription.class
edu/ntnu/stud/view/AffinePage.class
edu/ntnu/stud/controller/SceneController.class
edu/ntnu/stud/model/ChaosGame.class
edu/ntnu/stud/model/Vector2D.class
Matrix2x2Test.class
AffineTransform2DTest.class
Vector2DTest$subtractVectorTests.class
Vector2DTest$addVectorTests.class
Vector2DTest$constructorTests.class
Vector2DTest$setX0Tests.class
Vector2DTest.class
Vector2DTest$getX0Tests.class
JuliaTransformTest.class
ComplexTest.class
/Users/johanarntsen/Documents/Programmering 2/idatt2003_gr43-programmering-2/src/test/java/AffineTransform2DTest.java
/Users/johanarntsen/Documents/Programmering 2/idatt2003_gr43-programmering-2/src/test/java/ComplexTest.java
/Users/johanarntsen/Documents/Programmering 2/idatt2003_gr43-programmering-2/src/test/java/JuliaTransformTest.java
/Users/johanarntsen/Documents/Programmering 2/idatt2003_gr43-programmering-2/src/test/java/Matrix2x2Test.java
/Users/johanarntsen/Documents/Programmering 2/idatt2003_gr43-programmering-2/src/test/java/Vector2DTest.java
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment