1
0
Fork 0

Changed the behaviour when the tree was finshed, it now is never finished until the squares are under a given pixel size

This commit is contained in:
Jan Christian Grünhage 2016-05-06 16:38:28 +02:00
parent 0177d8a9ae
commit 908889acd6
No known key found for this signature in database
GPG Key ID: 62BEE5EB8F370DC6
5 changed files with 61 additions and 17 deletions

View File

@ -117,6 +117,8 @@ public class Main {
variant = PythagorasTree.PythagorasTreeVariant.AsymetricPythagorasTree; variant = PythagorasTree.PythagorasTreeVariant.AsymetricPythagorasTree;
} else if (input.equalsIgnoreCase("RegularRandomPythagorasTree")) { } else if (input.equalsIgnoreCase("RegularRandomPythagorasTree")) {
variant = PythagorasTree.PythagorasTreeVariant.RegularRandomPythagorasTree; variant = PythagorasTree.PythagorasTreeVariant.RegularRandomPythagorasTree;
} else if (input.equalsIgnoreCase("RandomPythagorasTree")) {
variant = PythagorasTree.PythagorasTreeVariant.RandomPythagorasTree;
} else if (input.equalsIgnoreCase("PisanoPythagorasTreeOne")) { } else if (input.equalsIgnoreCase("PisanoPythagorasTreeOne")) {
variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeOne; variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeOne;
} else if (input.equalsIgnoreCase("PisanoPythagorasTreeTwo")) { } else if (input.equalsIgnoreCase("PisanoPythagorasTreeTwo")) {
@ -129,7 +131,7 @@ public class Main {
variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeFive; variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeFive;
} else if (input.equalsIgnoreCase("KilianEhrmannPythagorasTree")) { } else if (input.equalsIgnoreCase("KilianEhrmannPythagorasTree")) {
variant = PythagorasTree.PythagorasTreeVariant.KilianEhrmannPythagorasTree; variant = PythagorasTree.PythagorasTreeVariant.KilianEhrmannPythagorasTree;
} else variant = PythagorasTree.PythagorasTreeVariant.unselected; } else variant = variantFromArg(input);
return variant; return variant;
} }
@ -140,8 +142,10 @@ public class Main {
variant = PythagorasTree.PythagorasTreeVariant.SymetricPythagorasTree; variant = PythagorasTree.PythagorasTreeVariant.SymetricPythagorasTree;
} else if (input.equalsIgnoreCase("2")) { } else if (input.equalsIgnoreCase("2")) {
variant = PythagorasTree.PythagorasTreeVariant.AsymetricPythagorasTree; variant = PythagorasTree.PythagorasTreeVariant.AsymetricPythagorasTree;
} else if (input.equalsIgnoreCase("3")) { } else if (input.equalsIgnoreCase("31")) {
variant = PythagorasTree.PythagorasTreeVariant.RegularRandomPythagorasTree; variant = PythagorasTree.PythagorasTreeVariant.RegularRandomPythagorasTree;
} else if (input.equalsIgnoreCase("32")) {
variant = PythagorasTree.PythagorasTreeVariant.RandomPythagorasTree;
} else if (input.equalsIgnoreCase("41")) { } else if (input.equalsIgnoreCase("41")) {
variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeOne; variant = PythagorasTree.PythagorasTreeVariant.PisanoPythagorasTreeOne;
} else if (input.equalsIgnoreCase("42")) { } else if (input.equalsIgnoreCase("42")) {
@ -206,14 +210,14 @@ public class Main {
} }
public static void variantHelp() { public static void variantHelp() {
System.out.println("SymetricPythagorasTree:"); System.out.println("SymetricPythagorasTree (1):");
System.out.println(""); System.out.println("");
System.out.println("This creates a normal symetric Pythagoras Tree."); System.out.println("This creates a normal symetric Pythagoras Tree.");
System.out.println(""); System.out.println("");
System.out.println(""); System.out.println("");
System.out.println(""); System.out.println("");
System.out.println("AsymetricPythagorasTree:"); System.out.println("AsymetricPythagorasTree (2):");
System.out.println(""); System.out.println("");
System.out.println("This creates an asymetric Pythagoras Tree."); System.out.println("This creates an asymetric Pythagoras Tree.");
System.out.println("The used angle will be adjustable later."); System.out.println("The used angle will be adjustable later.");
@ -221,7 +225,7 @@ public class Main {
System.out.println(""); System.out.println("");
System.out.println(""); System.out.println("");
System.out.println("RegularRandomPythagorasTree:"); System.out.println("RegularRandomPythagorasTree (3.1):");
System.out.println(""); System.out.println("");
System.out.println("This creates an asymetric Pythagoras Tree."); System.out.println("This creates an asymetric Pythagoras Tree.");
System.out.println("Each level of the tree will have it's own randomly generated angle."); System.out.println("Each level of the tree will have it's own randomly generated angle.");
@ -230,7 +234,16 @@ public class Main {
System.out.println(""); System.out.println("");
System.out.println(""); System.out.println("");
System.out.println("PisanoPythagorasTreeOne:"); System.out.println("RandomPythagorasTree (3.2):");
System.out.println("");
System.out.println("This creates an asymetric Pythagoras Tree.");
System.out.println("Each triangle of the tree will have it's own randomly generated angle.");
System.out.println("The generated angles will be between 20 and 70 degree.");
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("PisanoPythagorasTreeOne (4.1):");
System.out.println(""); System.out.println("");
System.out.println("This creates an asymetric Pythagoras Tree."); System.out.println("This creates an asymetric Pythagoras Tree.");
System.out.println("The angles used in this tree are generated from the Fractals.NumberCalculation.Fibonacci Numbers."); System.out.println("The angles used in this tree are generated from the Fractals.NumberCalculation.Fibonacci Numbers.");
@ -242,7 +255,7 @@ public class Main {
System.out.println(""); System.out.println("");
System.out.println(""); System.out.println("");
System.out.println("PisanoPythagorasTreeTwo:"); System.out.println("PisanoPythagorasTreeTwo: (4.2)");
System.out.println(""); System.out.println("");
System.out.println("The angles of this variant calculated like this: "); System.out.println("The angles of this variant calculated like this: ");
System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 2 multiplied by 30 plus 30"); System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 2 multiplied by 30 plus 30");
@ -250,7 +263,7 @@ public class Main {
System.out.println(""); System.out.println("");
System.out.println(""); System.out.println("");
System.out.println("PisanoPythagorasTreeThree:"); System.out.println("PisanoPythagorasTreeThree: (4.3)");
System.out.println(""); System.out.println("");
System.out.println("The angles of this variant calculated like this: "); System.out.println("The angles of this variant calculated like this: ");
System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 7 multiplied by 5 plus 30"); System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 7 multiplied by 5 plus 30");
@ -258,7 +271,7 @@ public class Main {
System.out.println(""); System.out.println("");
System.out.println(""); System.out.println("");
System.out.println("PisanoPythagorasTreeFour:"); System.out.println("PisanoPythagorasTreeFour: (4.4)");
System.out.println(""); System.out.println("");
System.out.println("The angles of this variant calculated like this: "); System.out.println("The angles of this variant calculated like this: ");
System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 31 plus 30"); System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 31 plus 30");
@ -266,7 +279,7 @@ public class Main {
System.out.println(""); System.out.println("");
System.out.println(""); System.out.println("");
System.out.println("PisanoPythagorasTreeFive:"); System.out.println("PisanoPythagorasTreeFive: (4.5)");
System.out.println(""); System.out.println("");
System.out.println("The angles of this variant calculated like this: "); System.out.println("The angles of this variant calculated like this: ");
System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 9 multiplied by 4 plus 29"); System.out.println("Fractals.NumberCalculation.Fibonacci number of the Level modulo 9 multiplied by 4 plus 29");
@ -274,7 +287,7 @@ public class Main {
System.out.println(""); System.out.println("");
System.out.println(""); System.out.println("");
System.out.println("KilianEhrmannPythagorasTree:"); System.out.println("KilianEhrmannPythagorasTree: (5)");
System.out.println(""); System.out.println("");
System.out.println("The angles of this variant calculated like this: "); System.out.println("The angles of this variant calculated like this: ");
System.out.println("(Don't ask why, just one of my classmates having fun...) "); System.out.println("(Don't ask why, just one of my classmates having fun...) ");

View File

@ -6,7 +6,7 @@ import java.util.LinkedList;
* Created by Christian on 10.02.2015. * Created by Christian on 10.02.2015.
*/ */
public class Fibonacci { public class Fibonacci {
LinkedList<Long> fibonacci = new LinkedList<Long>(); private LinkedList<Long> fibonacci = new LinkedList<Long>();
public Fibonacci() { public Fibonacci() {
fibonacci.add((long) 1); fibonacci.add((long) 1);

View File

@ -5,6 +5,7 @@ import ch.aplu.turtle.Turtle;
import Fractals.TurtleTools.TurtleState; import Fractals.TurtleTools.TurtleState;
import java.awt.*; import java.awt.*;
import static Fractals.TurtleTools.DrawingTools.drawSquare; import static Fractals.TurtleTools.DrawingTools.drawSquare;
/** /**
@ -19,6 +20,7 @@ public class PythagorasTree {
private double size; private double size;
private int momentaryDepth; private int momentaryDepth;
private int maximalDepth; private int maximalDepth;
private int minimalSize = 1;
private TurtleState turtleState; private TurtleState turtleState;
public PythagorasTree(PythagorasTreeVariant variant, PythagorasTriangleList triangles, Turtle turtle, double size, int momentaryDepth, int maximalDepth) { public PythagorasTree(PythagorasTreeVariant variant, PythagorasTriangleList triangles, Turtle turtle, double size, int momentaryDepth, int maximalDepth) {
@ -35,15 +37,18 @@ public class PythagorasTree {
if (queue.size() == 0) return false; if (queue.size() == 0) return false;
PythagorasTree tree = queue.remove(); PythagorasTree tree = queue.remove();
if (tree.momentaryDepth > tree.maximalDepth) return true; if (tree.momentaryDepth > tree.maximalDepth && tree.size <= tree.minimalSize) {
return true;
}
tree.turtle.getFrame().setTitle("Pythagoras Tree - Depth: " + tree.momentaryDepth + " - Target Depth: " + tree.maximalDepth + " - Queuesize: " + queue.size()); tree.turtle.getFrame().setTitle("Pythagoras Tree - Depth: " + tree.momentaryDepth + " - Target Depth: " + tree.maximalDepth + " - Queuesize: " + queue.size());
tree.turtle.setPenColor(drawColor(tree.momentaryDepth, tree.maximalDepth)); tree.turtle.setPenColor(drawColor(tree.momentaryDepth, tree.maximalDepth));
tree.turtleState.returnToState(tree.turtle); tree.turtleState.returnToState(tree.turtle);
drawSquare(tree.turtle, tree.size); drawSquare(tree.turtle, tree.size);
if (tree.momentaryDepth >= tree.maximalDepth) return true; if (tree.momentaryDepth >= tree.maximalDepth && tree.size < tree.minimalSize) {
return true;
}
tree.turtle.forward(tree.size); tree.turtle.forward(tree.size);
@ -65,6 +70,7 @@ public class PythagorasTree {
return true; return true;
} }
public static Color drawColor(int momentaryDepth, int maximalDepth) { public static Color drawColor(int momentaryDepth, int maximalDepth) {
double colorFactor = 255 / maximalDepth; double colorFactor = 255 / maximalDepth;
@ -73,14 +79,16 @@ public class PythagorasTree {
if (red > 139) red = 139; if (red > 139) red = 139;
if (red < 0) red = 0; if (red < 0) red = 0;
int green = 255 - (int) (colorFactor * (maximalDepth - momentaryDepth)); int green = 255 - (int) (colorFactor * (maximalDepth - momentaryDepth));
if (green > 255) green = 255;
if (green < 69) green = 69; if (green < 69) green = 69;
int blue = (int) (colorFactor * ((maximalDepth - momentaryDepth) / 5)); int blue = (int) (colorFactor * ((maximalDepth - momentaryDepth) / 5));
if (blue > 19) blue = 19; if (blue > 19) blue = 19;
if (blue < 0) blue = 0;
return new Color(red, green, blue); return new Color(red, green, blue);
} }
public enum PythagorasTreeVariant { public enum PythagorasTreeVariant {
SymetricPythagorasTree, AsymetricPythagorasTree, RegularRandomPythagorasTree, SymetricPythagorasTree, AsymetricPythagorasTree, RegularRandomPythagorasTree, RandomPythagorasTree,
PisanoPythagorasTreeOne, PisanoPythagorasTreeTwo, PisanoPythagorasTreeThree, PisanoPythagorasTreeFour, PisanoPythagorasTreeFive, PisanoPythagorasTreeOne, PisanoPythagorasTreeTwo, PisanoPythagorasTreeThree, PisanoPythagorasTreeFour, PisanoPythagorasTreeFive,
KilianEhrmannPythagorasTree, KilianEhrmannPythagorasTree,
unselected, unselected,

View File

@ -12,9 +12,12 @@ public class PythagorasTriangle {
private double leftAngle; private double leftAngle;
private double rightSizeFactor; private double rightSizeFactor;
private double rightAngle; private double rightAngle;
boolean irregularRandom;
public PythagorasTriangle(PythagorasTree.PythagorasTreeVariant variant, int momentaryDepth, Fibonacci fibonacci, Double angle) { public PythagorasTriangle(PythagorasTree.PythagorasTreeVariant variant, int momentaryDepth, Fibonacci fibonacci, Double angle) {
irregularRandom = false;
switch (variant) { switch (variant) {
@ -34,6 +37,13 @@ public class PythagorasTriangle {
break; break;
case RandomPythagorasTree:
leftAngle = 0;
irregularRandom = true;
//Calculation in here doesn't matter, will get overridden later.
break;
case PisanoPythagorasTreeOne: case PisanoPythagorasTreeOne:
leftAngle = (fibonacci.calcFibonacci(momentaryDepth) % 4) * 10 + 30; leftAngle = (fibonacci.calcFibonacci(momentaryDepth) % 4) * 10 + 30;
break; break;
@ -92,6 +102,12 @@ public class PythagorasTriangle {
} }
public double getLeftAngle() { public double getLeftAngle() {
if (irregularRandom) {
leftAngle = Math.random() * 50 + 20;
rightAngle = (double) 90 - leftAngle;
leftSizeFactor = Math.sin(Math.toRadians(leftAngle));
rightSizeFactor = Math.sin(Math.toRadians(rightAngle));
}
return leftAngle; return leftAngle;
} }

View File

@ -10,14 +10,21 @@ import Fractals.NumberCalculation.Fibonacci;
public class PythagorasTriangleList { public class PythagorasTriangleList {
private LinkedList<PythagorasTriangle> triangles = new LinkedList<PythagorasTriangle>(); private LinkedList<PythagorasTriangle> triangles = new LinkedList<PythagorasTriangle>();
private Fibonacci fibonacci = new Fibonacci(); private Fibonacci fibonacci = new Fibonacci();
private PythagorasTree.PythagorasTreeVariant variant;
private double angle;
public PythagorasTriangleList(PythagorasTree.PythagorasTreeVariant variant, double maximalDepth, double angle) { public PythagorasTriangleList(PythagorasTree.PythagorasTreeVariant variant, int maximalDepth, double angle) {
this.variant = variant;
this.angle = angle;
for (int i = 0; i < maximalDepth; i++) { for (int i = 0; i < maximalDepth; i++) {
triangles.add(new PythagorasTriangle(variant, i, fibonacci, angle)); triangles.add(new PythagorasTriangle(variant, i, fibonacci, angle));
} }
} }
public double getLeftAngle(int index) { public double getLeftAngle(int index) {
if (index >= triangles.size()) {
triangles.add(new PythagorasTriangle(variant, index, fibonacci, angle));
}
return triangles.get(index).getLeftAngle(); return triangles.get(index).getLeftAngle();
} }