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

Improved putPixel()-method to account for negative indices, which previously...

Improved putPixel()-method to account for negative indices, which previously cause error when trying to produce Barnsley fern.
parent a24bf4cc
No related branches found
No related tags found
No related merge requests found
......@@ -17,16 +17,19 @@ public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.println("Hi");
String path = "src/main/resources/descriptions/sierpinski.txt";
String path = "src/main/resources/descriptions/templates/sierpinski.txt";
ChaosGameDescription description = null; // Declare description
ChaosGame game = null;
ChaosGameDescriptionFactory factory = new ChaosGameDescriptionFactory();
try {
//ChaosGameDescription description = new ChaosGameFileHandler().readFromFile(path);
//description = new ChaosGameDescription(minCoords, maxCoords, transforms);
description = new ChaosGameFileHandler().readFromFile(path);
//description = new ChaosGameFileHandler().readFromFile(path);
description = factory.getDescriptions().get(1);
ChaosCanvas canvas = new ChaosCanvas(100, 100, description.getMinCoords(), description.getMaxCoords()); // Create canvas
game = new ChaosGame(description, canvas);
......@@ -54,8 +57,8 @@ public class Main {
if (Objects.equals(sc.next(), "1")) {
ChaosGameFileHandler handler = new ChaosGameFileHandler();
handler.writeToFile(description, "src/main/resources/descriptions/output.txt");
System.out.println("Wrote to file output.txt.");
handler.writeToFile(description, "src/main/resources/descriptions/output/output_1.txt");
System.out.println("Wrote to file output_1.txt.");
}
else {
exit = true;
......
......@@ -78,9 +78,21 @@ public class ChaosCanvas {
[(int) transformCoordsToIndices.transform(point).getX1()];
}
/**
* Place a pixel on the canvas.
*
* @param point the point where the pixel is to be placed.
*/
public void putPixel(Vector2D point) {
canvas[(int) transformCoordsToIndices.transform(point).getX0()]
[(int) transformCoordsToIndices.transform(point).getX1()] = 1;
int xOffset = (int) Math.abs(minCoords.getX0());
int yOffset = (int) Math.abs(minCoords.getX1());
int xIndex = (int) transformCoordsToIndices.transform(point).getX0() + xOffset;
int yIndex = (int) transformCoordsToIndices.transform(point).getX1() + yOffset;
if (xIndex >= 0 && xIndex < width && yIndex >= 0 && yIndex < height) {
canvas[xIndex][yIndex] = 1;
}
}
/**
......
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
0.0, 0.0, 0.0, 0.16, 0.0, 0.0
0.85, 0.04, -0.04, 0.85, 0.0, 1.6
0.2, -0.26, 0.23, 0.22, 0.0, 0.16
-0.15, 0.28, 0.26, 0.24, 0, 0.44
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