Skip to content
Snippets Groups Projects
Commit f39b7b84 authored by Håvard Daleng's avatar Håvard Daleng
Browse files

Created ChaosGameDescriptionFactory and added 5 files containing data....

Created ChaosGameDescriptionFactory and added 5 files containing data. Currently they containthe same data, this should be changed later.
parent cfc2b78b
No related branches found
No related tags found
No related merge requests found
Showing
with 107 additions and 22 deletions
package edu.ntnu.stud.chaosgame;
import edu.ntnu.stud.chaosgame.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.game.ChaosGameFileHandler;
import edu.ntnu.stud.chaosgame.model.Matrix2x2;
import edu.ntnu.stud.chaosgame.model.Vector2D;
import edu.ntnu.stud.chaosgame.model.handling.ChaosCanvas;
import edu.ntnu.stud.chaosgame.model.handling.ChaosGame;
import edu.ntnu.stud.chaosgame.model.transformations.AffineTransform2D;
import edu.ntnu.stud.chaosgame.model.transformations.Transform2D;
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.model.generators.ChaosGameDescriptionFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Scanner;
......@@ -36,7 +31,12 @@ public class Main {
game = new ChaosGame(description, canvas);
} catch (Exception e) {
System.out.println(e.getMessage()); // TODO: Alter error handling
System.out.println(e.getMessage()); // TODO: Alter error game
}
ChaosGameDescriptionFactory factory = new ChaosGameDescriptionFactory();
for (ChaosGameDescription desc : factory.getDescriptions()) {
System.out.println(desc);
}
boolean exit = false;
......
package edu.ntnu.stud.chaosgame.model;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription;
/**
* Class representing a 2x2 matrix.
*/
......@@ -50,7 +52,7 @@ public class Matrix2x2 {
}
/**
* Getter method for {@link edu.ntnu.stud.chaosgame.game.ChaosGameDescription}
* Getter method for {@link ChaosGameDescription}
* @return a matrix component.
*/
public double getA00() {
......@@ -58,7 +60,7 @@ public class Matrix2x2 {
}
/**
* Getter method for {@link edu.ntnu.stud.chaosgame.game.ChaosGameDescription}
* Getter method for {@link ChaosGameDescription}
* @return a matrix component.
*/
public double getA01() {
......@@ -66,7 +68,7 @@ public class Matrix2x2 {
}
/**
* Getter method for {@link edu.ntnu.stud.chaosgame.game.ChaosGameDescription}
* Getter method for {@link ChaosGameDescription}
* @return a matrix component.
*/
public double getA10() {
......@@ -74,7 +76,7 @@ public class Matrix2x2 {
}
/**
* Getter method for {@link edu.ntnu.stud.chaosgame.game.ChaosGameDescription}
* Getter method for {@link ChaosGameDescription}
* @return a matrix component.
*/
public double getA11() {
......
package edu.ntnu.stud.chaosgame.model.handling;
package edu.ntnu.stud.chaosgame.model.game;
import edu.ntnu.stud.chaosgame.model.Matrix2x2;
import edu.ntnu.stud.chaosgame.model.Vector2D;
......
package edu.ntnu.stud.chaosgame.model.handling;
package edu.ntnu.stud.chaosgame.model.game;
import edu.ntnu.stud.chaosgame.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.model.Vector2D;
import java.util.Random;
......
package edu.ntnu.stud.chaosgame.game;
package edu.ntnu.stud.chaosgame.model.game;
import edu.ntnu.stud.chaosgame.model.Vector2D;
......
package edu.ntnu.stud.chaosgame.game;
package edu.ntnu.stud.chaosgame.model.game;
import edu.ntnu.stud.chaosgame.model.Complex;
import edu.ntnu.stud.chaosgame.model.Matrix2x2;
......
package edu.ntnu.stud.chaosgame.model.generators;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
/**
* Class that generates a set number of ChaosGameDescription instances using a set of
* files read by a ChaosGameFileHandler.
*/
public class ChaosGameDescriptionFactory {
/**
* The list of all the descriptions generated from the data in the directory specified
* in constructor.
*/
private final ArrayList<ChaosGameDescription> descriptions;
/**
* Generate ChaosGameDescription-instances based on data in txt-files found in the directory.
* The naming of the txt-files must follow the pattern "desc_X.txt" where X is an integer
* incremented by 1 for each file in the directory.
*
* @throws IOException if the method fails to read successfully from one of the data files.
*/
public ChaosGameDescriptionFactory() throws IOException {
/**
* The directory where the descriptions are located.
*/
String directory1 = "src/main/resources/descriptions/factory/";
this.descriptions = new ArrayList<>();
ChaosGameFileHandler handler = new ChaosGameFileHandler();
File directory = new File(directory1);
int fileCount = Objects.requireNonNull(directory.list()).length;
for (int i = 0; i < fileCount; i++) {
this.descriptions.add(handler.readFromFile(directory1 + "desc_" + (i + 1) + ".txt"));
}
}
/**
* Get the list of descriptions.
*
* @return the list.
*/
public ArrayList<ChaosGameDescription> getDescriptions() { return this.descriptions; }
}
......@@ -2,6 +2,7 @@ package edu.ntnu.stud.chaosgame.model.transformations;
import edu.ntnu.stud.chaosgame.model.Matrix2x2;
import edu.ntnu.stud.chaosgame.model.Vector2D;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler;
/**
* Represents affine transformations in a 2D-plane by extending the abstract
......@@ -43,7 +44,7 @@ public class AffineTransform2D extends Transform2D {
}
/**
* Getter method to use with {@link edu.ntnu.stud.chaosgame.game.ChaosGameFileHandler}
* Getter method to use with {@link ChaosGameFileHandler}
* @return The matrix for the transformation
*/
public Matrix2x2 getMatrix(){return this.matrix;}
......
......@@ -2,6 +2,7 @@ package edu.ntnu.stud.chaosgame.model.transformations;
import edu.ntnu.stud.chaosgame.model.Complex;
import edu.ntnu.stud.chaosgame.model.Vector2D;
import edu.ntnu.stud.chaosgame.model.game.ChaosGameFileHandler;
public class JuliaTransform extends Transform2D {
......@@ -54,7 +55,7 @@ public class JuliaTransform extends Transform2D {
}
/**
* Getter method to use with {@link edu.ntnu.stud.chaosgame.game.ChaosGameFileHandler}
* Getter method to use with {@link ChaosGameFileHandler}
* @return The complex number used in the transformation.
*/
public Complex getC1(){return this.c1;}
......
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
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
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
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
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
......@@ -3,6 +3,7 @@ package edu.ntnu.stud.chaosgame.game;
import edu.ntnu.stud.chaosgame.model.Complex;
import edu.ntnu.stud.chaosgame.model.Matrix2x2;
import edu.ntnu.stud.chaosgame.model.Vector2D;
import edu.ntnu.stud.chaosgame.model.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;
......
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