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

Created basic ChaosGame-class

parent 42235b57
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,8 @@ import edu.ntnu.stud.chaosgame.game.ChaosGameDescription; ...@@ -4,6 +4,8 @@ import edu.ntnu.stud.chaosgame.game.ChaosGameDescription;
import edu.ntnu.stud.chaosgame.game.ChaosGameFileHandler; import edu.ntnu.stud.chaosgame.game.ChaosGameFileHandler;
import edu.ntnu.stud.chaosgame.model.Matrix2x2; import edu.ntnu.stud.chaosgame.model.Matrix2x2;
import edu.ntnu.stud.chaosgame.model.Vector2D; 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.AffineTransform2D;
import edu.ntnu.stud.chaosgame.model.transformations.Transform2D; import edu.ntnu.stud.chaosgame.model.transformations.Transform2D;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -27,15 +29,20 @@ public class Main { ...@@ -27,15 +29,20 @@ public class Main {
List<Transform2D> transforms = new ArrayList<>(); List<Transform2D> transforms = new ArrayList<>();
transforms.add(affineTransform); transforms.add(affineTransform);
ChaosGameDescription description = null; // Declare description
ChaosGame game = null;
try { try {
//ChaosGameDescription description = new ChaosGameFileHandler().readFromFile(path); //ChaosGameDescription description = new ChaosGameFileHandler().readFromFile(path);
ChaosGameDescription description = new ChaosGameDescription(minCoords, maxCoords, transforms); description = new ChaosGameDescription(minCoords, maxCoords, transforms);
System.out.println("MaxCoords-object of description: " + description.getMaxCoords()); System.out.println("MaxCoords-object of description: " + description.getMaxCoords());
ChaosCanvas canvas = new ChaosCanvas(100, 100, minCoords, maxCoords); // Create canvas
game = new ChaosGame(description, canvas);
} catch (Exception e) { } catch (Exception e) {
System.out.println(e.getMessage()); // TODO: Alter error handling System.out.println(e.getMessage()); // TODO: Alter error handling
} }
game.runSteps(100);
} }
......
...@@ -32,11 +32,39 @@ public class ChaosGame { ...@@ -32,11 +32,39 @@ public class ChaosGame {
/** /**
* The random number generator for the chaos game. * The random number generator for the chaos game.
*/ */
public Random random; private Random random;
/**
* Number of transforms
*/
private int numOfTransforms;
public ChaosGame(ChaosGameDescription description, ChaosCanvas canvas) { public ChaosGame(ChaosGameDescription description, ChaosCanvas canvas) {
this.canvas = canvas; this.canvas = canvas;
this.description = description; this.description = description;
this.random = new Random();
this.numOfTransforms = description.getTransforms().size();
this.currentPoint = new Vector2D(0, 0);
}
/**
* Get the canvas of this chaos game.
* @return the canvas.
*/
public ChaosCanvas getCanvas() { return this.canvas; }
/**
* Run the chaos game for n iterations.
*
* @param n the number of iterations
*/
public void runSteps(int n) {
for (int i = 0; i < n; i++) {
int j = this.random.nextInt(0, this.numOfTransforms);
j = 0;
this.currentPoint = this.description.getTransforms().get(j).transform(currentPoint);
this.canvas.putPixel(currentPoint);
}
} }
} }
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