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

Move game to controller, fix comment handling in readFromFile

parent 86729d84
No related branches found
No related tags found
No related merge requests found
Showing
with 59 additions and 53 deletions
package edu.ntnu.stud.chaosgame;
import edu.ntnu.stud.chaosgame.controller.ChaosGameButtonController;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler;
import edu.ntnu.stud.chaosgame.model.game.ChaosCanvas;
import edu.ntnu.stud.chaosgame.model.game.ChaosGame;
import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.controller.game.ChaosGameFileHandler;
import edu.ntnu.stud.chaosgame.controller.game.ChaosCanvas;
import edu.ntnu.stud.chaosgame.controller.game.ChaosGame;
import edu.ntnu.stud.chaosgame.model.generators.ChaosGameDescriptionFactory;
import edu.ntnu.stud.chaosgame.view.ChaosGameGUIView;
import javafx.application.Application;
......
package edu.ntnu.stud.chaosgame.controller;
import edu.ntnu.stud.chaosgame.model.game.ChaosCanvas;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.controller.game.ChaosCanvas;
import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription;
/**
* Observer class for monitoring changes to the active
......
package edu.ntnu.stud.chaosgame.model.game;
package edu.ntnu.stud.chaosgame.controller.game;
import edu.ntnu.stud.chaosgame.model.data.Matrix2x2;
import edu.ntnu.stud.chaosgame.model.data.Vector2D;
......
package edu.ntnu.stud.chaosgame.model.game;
package edu.ntnu.stud.chaosgame.controller.game;
import edu.ntnu.stud.chaosgame.model.data.Vector2D;
import java.util.Random;
......
package edu.ntnu.stud.chaosgame.model.game;
package edu.ntnu.stud.chaosgame.controller.game;
import edu.ntnu.stud.chaosgame.model.data.Vector2D;
......
package edu.ntnu.stud.chaosgame.model.game;
package edu.ntnu.stud.chaosgame.controller.game;
import edu.ntnu.stud.chaosgame.model.data.Complex;
import edu.ntnu.stud.chaosgame.model.data.Matrix2x2;
......@@ -34,11 +34,15 @@ public class ChaosGameFileHandler {
scanner.useLocale(Locale.ENGLISH);
// Use a delimiter that splits on commas and new lines, and ignores comment lines.
scanner.useDelimiter("\\s*,\\s*|\\s*\\r?\\n+\\s*|(?m)^#.*$");
scanner.useDelimiter(",\\s*|\\r?\\n|(\\s*#.*\\s*)");
String firstLine = scanner.next().trim();
String firstLine = scanner.nextLine().trim();
if (firstLine.equals("Affine2D")) {
// Read the minimum vector
if (scanner.hasNextDouble()) {
double x0min = scanner.nextDouble();
......
package edu.ntnu.stud.chaosgame.model.data;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription;
/**
* Class representing a 2x2 matrix.
......
package edu.ntnu.stud.chaosgame.model.generators;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler;
import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.controller.game.ChaosGameFileHandler;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
......
......@@ -2,7 +2,7 @@ package edu.ntnu.stud.chaosgame.model.transformations;
import edu.ntnu.stud.chaosgame.model.data.Matrix2x2;
import edu.ntnu.stud.chaosgame.model.data.Vector2D;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler;
import edu.ntnu.stud.chaosgame.controller.game.ChaosGameFileHandler;
/**
* Represents affine transformations in a 2D-plane by extending the abstract
......
......@@ -2,7 +2,7 @@ package edu.ntnu.stud.chaosgame.model.transformations;
import edu.ntnu.stud.chaosgame.model.data.Complex;
import edu.ntnu.stud.chaosgame.model.data.Vector2D;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler;
import edu.ntnu.stud.chaosgame.controller.game.ChaosGameFileHandler;
public class JuliaTransform extends Transform2D {
......
package edu.ntnu.stud.chaosgame.view;
import edu.ntnu.stud.chaosgame.controller.ChaosGameButtonController;
import edu.ntnu.stud.chaosgame.model.game.ChaosCanvas;
import edu.ntnu.stud.chaosgame.model.game.ChaosGame;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription;
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.scene.Scene;
......@@ -64,7 +64,7 @@ public class ChaosGameGUIView {
//TEMPORARY CODE to test Chaos Games in GUI
ChaosGameDescriptionFactory factory = new ChaosGameDescriptionFactory();
ChaosGameDescription description = factory.getDescriptions().get(1);
ChaosGameDescription description = factory.getDescriptions().get(2);
ChaosCanvas canvas = new ChaosCanvas(1000, 1000, description.getMinCoords(), description.getMaxCoords());
game = new ChaosGame(description, canvas);
......@@ -74,7 +74,7 @@ public class ChaosGameGUIView {
public void drawChaosGame(){
ChaosCanvas canvas = game.getCanvas();
game.runSteps(100000);
game.runSteps(1000);
// Test implementation for drawing fractals
int[][] betaArray = canvas.getCanvasArray();
......@@ -88,6 +88,7 @@ public class ChaosGameGUIView {
}
}
public int getWidth(){
......
Affine2D
0.0, 0.0
1.0, 1.0
0.5, 0.0, 0.0, 0.5, 0.0, 0.0
0.5, 0.0, 0.0, 0.5, 0.25, 0.5
0.5, 0.0, 0.0, 0.5, 0.5, 0.0
Affine2D # Comment
0.0, 0.0 # Comment
1.0, 1.0 # Comment
0.5, 0.0, 0.0, 0.5, 0.0, 0.0 # Comment
0.5, 0.0, 0.0, 0.5, 0.25, 0.5 # Comment
0.5, 0.0, 0.0, 0.5, 0.5, 0.0 # Comment
Affine2D
-2.65, 0
2.65, 10
0, 0, 0, .16, 0, 0
.85, .04, -.04, .85, 0, 1.6
.2, -.26, .23, .22, 0, 1.6
-.15, .28, .26, .24, 0, .44
\ No newline at end of file
Affine2D # Comment
-2.65, 0 # Comment
2.65, 10 # Comment
0, 0, 0, .16, 0, 0 # Comment
.85, .04, -.04, .85, 0, 1.6 # Comment
.2, -.26, .23, .22, 0, 1.6 # Comment
-.15, .28, .26, .24, 0, .44 # Comment
\ No newline at end of file
Julia
-1.6, -1
1.6, 1
-.74543, .11301
\ No newline at end of file
Julia # Comment
-1.6, -1 # Comment
1.6, 1 # Comment
-.74543, .11301 # Comment
\ No newline at end of file
......@@ -3,7 +3,7 @@ package edu.ntnu.stud.chaosgame.game;
import edu.ntnu.stud.chaosgame.model.data.Complex;
import edu.ntnu.stud.chaosgame.model.data.Matrix2x2;
import edu.ntnu.stud.chaosgame.model.data.Vector2D;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.model.transformations.AffineTransform2D;
import edu.ntnu.stud.chaosgame.model.transformations.JuliaTransform;
import edu.ntnu.stud.chaosgame.model.transformations.Transform2D;
......
......@@ -4,8 +4,8 @@ package edu.ntnu.stud.chaosgame.game;
import edu.ntnu.stud.chaosgame.model.data.Complex;
import edu.ntnu.stud.chaosgame.model.data.Matrix2x2;
import edu.ntnu.stud.chaosgame.model.data.Vector2D;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler;
import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.controller.game.ChaosGameFileHandler;
import edu.ntnu.stud.chaosgame.model.transformations.AffineTransform2D;
import edu.ntnu.stud.chaosgame.model.transformations.JuliaTransform;
import edu.ntnu.stud.chaosgame.model.transformations.Transform2D;
......@@ -28,12 +28,12 @@ class ChaosGameFileHandlerTest {
@Test
void testReadFromFileAffine2D() throws IOException {
String fileContent = """
Affine2D
0.0, 0.0
1.0, 1.0
0.5, 1.0, 1.0, 0.5, 3.0, 1.0
0.5, 1.0, 1.0, 0.5, 3.0, 1.0
0.5, 1.0, 1.0, 0.5, 3.0, 1.0
Affine2D # Comment
0.0, 0.0 # Comment
1.0, 1.0 # Comment
0.5, 1.0, 1.0, 0.5, 3.0, 1.0 # Comment
0.5, 1.0, 1.0, 0.5, 3.0, 1.0 # Comment
0.5, 1.0, 1.0, 0.5, 3.0, 1.0 # Comment
""";
Path tempFile = Files.createTempFile("test", ".txt");
......@@ -44,6 +44,8 @@ class ChaosGameFileHandlerTest {
Vector2D minCoords = description.getMinCoords();
Vector2D maxCoords = description.getMaxCoords();
assertEquals(0.0, minCoords.getX0());
assertEquals(0.0, minCoords.getX1());
assertEquals(1.0, maxCoords.getX0());
......@@ -67,10 +69,10 @@ class ChaosGameFileHandlerTest {
@Test
void testReadFromFileJulia() throws IOException {
String fileContent = """
Julia
-1.6, -1
1.6, 1
-.74543, .11301
Julia # Comment \n
-1.6, -1 # Comment \n
1.6, 1 # Comment \n
-.74543, .11301 # Comment
""";
Path tempFile = Files.createTempFile("test", ".txt");
......
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