diff --git a/2017-03-05 (5).png b/2017-03-05 (5).png new file mode 100644 index 0000000..3c9a4c2 Binary files /dev/null and b/2017-03-05 (5).png differ diff --git a/README.md b/README.md index f9f1529..a7c8c85 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The purpose of this project is to create visually apealing trees in Java using T ### Change it to your liking! It is easy modify many properties of the trees. Here is a list of the things you can change in this code. -1. **Number of child branches.** +1. **Number of trees.** Just add more Tree objects `Tree tree = new Tree(15);` to main. ```Java public static void main(String[] args) { @@ -21,19 +21,15 @@ Just add more Tree objects `Tree tree = new Tree(15);` to main. 2. **Size of trees** use `tree.setSize(size);` to change the size of the tree. 3. **Positions** -use `setPositionX(int positionX)` and `setPositionY(int positionY)` to set position of the root branch. The value of X starts at 0 and increases from left to right of your screen, while the Y value starts at 0 and increases from top to bottom of your screen. 3. **Angle position of trees** -use `tree.setTreeAngle(angle);` to set the angle of the tree. Angle is measured in counter-clockwise degrees, where 0 is the right-most of the screen and 180 is the left-most of the screen. +use `tree.setTreeAngle(angle);` to set the angle of the tree. Angle is measured in counter-clockwise degrees, where 0 is the right-most of the screen and 180 is the left-most of the screen. 3. **Angle separation** -use `tree.setSeparationAngle(Angle);` to set the angle seperation between branches. This angle will dictate how far appart should each branch be from its sibling branch. You can get funny/interesiting looking trees if you play with this property. Try setting it to 60, 90, or more if you want to have crazy looking trees. +use `tree.setSeparationAngle(Angle);` to set the angle seperation between branches. This angle will dictate how far appart should each branch be from its sibling branch. You can get funny/interesiting looking trees if you play with this property. + 5. **Delay between paintings** -The Tree class has a method `slowMotion()` which aesthetically draws the tree, by reducing the time between frames. -If you wish to use a constant time between frames you have to manually add `delay(long delay)` in the method `drawTree()` instead of using `slowMotion()`. -Further development is needed easily switch between these settings at optimal performance. ### Done! -Note: All setting might be overwritten if the safety is on. -After you are done editing your tree, just call `tree.draw(boolean safety);` to draw it! +After you are done editing your tree, just call `tree.draw();` to draw it! ![alt text](https://github.com/Maickii/Java_Tree/blob/master/2017-03-05%20(2).png "Tree") diff --git a/Tree/README.md b/Tree/README.md new file mode 100644 index 0000000..fec5601 --- /dev/null +++ b/Tree/README.md @@ -0,0 +1 @@ +# Hello diff --git a/Tree/bin/TreeMain/Paint.class b/Tree/bin/TreeMain/Paint.class new file mode 100644 index 0000000..331d1f8 Binary files /dev/null and b/Tree/bin/TreeMain/Paint.class differ diff --git a/Tree/bin/TreeMain/Tree.class b/Tree/bin/TreeMain/Tree.class new file mode 100644 index 0000000..1a98dd6 Binary files /dev/null and b/Tree/bin/TreeMain/Tree.class differ diff --git a/Tree/src/TreeMain/Paint.java b/Tree/src/TreeMain/Paint.java new file mode 100644 index 0000000..3764e9f --- /dev/null +++ b/Tree/src/TreeMain/Paint.java @@ -0,0 +1,59 @@ +package TreeMain; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.util.ArrayList; + +import javax.swing.JComponent; + +import java.awt.geom.Ellipse2D.Double; +import java.awt.geom.Ellipse2D; +import java.awt.geom.Line2D; +import java.awt.geom.Point2D; + +public class Paint extends JComponent{ + + private static ArrayList lines = new ArrayList(); + private static ArrayList circles = new ArrayList(); + private static ArrayList circleColors = new ArrayList(); + private static ArrayList lineColors = new ArrayList(); + private static Color defaultColor = new Color(165,42,42); + private static BasicStroke defaulltStrokeWidth = new BasicStroke(3); + + public void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D)g; + + + for (int line = 0; line < lines.size(); line++) + { + g2.setColor(defaultColor); + if (lineColors.get(line) != null){ + g2.setColor(lineColors.get(line)); + } + g2.setStroke(defaulltStrokeWidth); + g2.draw(lines.get(line)); + } + + for (int circle = 0; circle < circles.size(); circle++) + { + g2.setColor(circleColors.get(circle)); + g2.fill(circles.get(circle)); + } + + } + + public void addLine(Line2D line, Color color) + { + lines.add(line); + lineColors.add(color); + } + + public void addCircle(Point2D point2d, Color color) + { + circles.add(new Ellipse2D.Double(point2d.getX()-5,point2d.getY()-5,10,10)); + circleColors.add(color); + } +} diff --git a/Tree/src/TreeMain/Tree.java b/Tree/src/TreeMain/Tree.java new file mode 100644 index 0000000..8bc49e8 --- /dev/null +++ b/Tree/src/TreeMain/Tree.java @@ -0,0 +1,160 @@ +package TreeMain; + +import java.awt.Color; +import java.awt.Point; +import java.awt.geom.Line2D; +import java.awt.geom.Point2D; +import java.util.Random; + +import javax.swing.JFrame; + +public class Tree { + boolean holder = false; + static Paint paint = new Paint(); + private Random random = new Random(); + private static JFrame frame; + public static void main(String[] args) { + + new Tree(270, 960, 900, 120); + //new Tree(240, 1095, 615, 50); + //new Tree(300, 825, 615, 50); + } + + public Tree() { + initFrame(); + Line2D trunk = new Line2D.Double(960, 900, 960, 850); + makeBranch(trunk, null); + trunk = new Line2D.Double(1250, 700, 1270, 650); + makeBranch(trunk, null); + } + + // need to make a method that creates a tree only needing angle, length, and + // coords as parameters + public Tree(double angle, Point2D pointA, double length) { + initFrame(); + Point2D pointB = getPointB(angle, pointA, length); + Line2D trunk = new Line2D.Double(pointA.getX(), pointA.getY(), pointB.getX(), pointB.getY()); + makeBranch(trunk, null); + } + + public Tree(double angle, int x_pos, int y_pos, double length) { + initFrame(); + Point.Double pointA = new Point.Double(x_pos, y_pos); + Point2D pointB = getPointB(angle, pointA, length); + Line2D trunk = new Line2D.Double(pointA.getX(), pointA.getY(), pointB.getX(), pointB.getY()); + makeBranch(trunk, null); + } + + public void initFrame() { + if (frame != null) + { + return; + } + frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(1920, 1080); + frame.setResizable(false); + frame.setTitle("Tree"); + frame.getContentPane().setBackground(Color.WHITE); + frame.setExtendedState(JFrame.MAXIMIZED_BOTH); + frame.setUndecorated(true); + frame.setVisible(true); + frame.add(paint); + frame.setEnabled(true); + } + + // private double generateRanges150To210() + // { + // holder = !holder; + // if(holder) + // { + // return 150; + // } + // if(!holder) + // { + // return 210; + // } + // + // return 0; + //// return random.nextInt(61) +150; + // } + // steps: + // find the length the original line + // knowing and angle and the length of the original line, find the length of + // the next line + // + private void makeBranch(Line2D line, Color color) { + if (getDistanceOfLine(line) <= 4) { + paint.addCircle(line.getP1(), color); + return; + } + + if (getDistanceOfLine(line) <= 120 || color == null) { + color = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)); + } + + paint.addLine(line, color); + //slowMotion(); + Point.Double pointA = getPointB(toLineAngle(line, 150), line.getP2(), getDistanceOfLine(line) - 10); + Line2D branchLine = new Line2D.Double(line.getX2(), line.getY2(), pointA.getX(), pointA.getY()); + + Point.Double pointB = getPointB(toLineAngle(line, 210), line.getP2(), getDistanceOfLine(line) - 10); + Line2D branchLine2 = new Line2D.Double(line.getX2(), line.getY2(), pointB.getX(), pointB.getY()); + + frame.repaint(); + makeBranch(branchLine, color); + makeBranch(branchLine2, color); + + } + + private double getDistanceOfLine(Line2D line) { + Point2D pointA = line.getP1(); + Point2D pointB = line.getP2(); + + return Math.abs( + Math.sqrt(Math.pow(pointB.getX() - pointA.getX(), 2) + Math.pow(pointB.getY() - pointA.getY(), 2))); + + } + + private double toLineAngle(Line2D line, double angle) { + return getAngle(line) + angle; + } + + private double getAngle(Line2D line) { + double height = line.getY1() - line.getY2(); + double width = line.getX2() - line.getX1(); + double angle = Math.toDegrees(Math.atan2(height, width)); + return angle; + } + + /** + * getPointB() calculates a the second point "pointB" in relation to point + * "pointA" at the given angle and length + * + * @param angle + * @param point2d + * @param length + * @return + */ + private Point.Double getPointB(double angle, Point2D pointA, double length) { + // System.out.println(Math.cos(Math.toRadians(angle)) * length); + double xLocation = (-Math.cos(Math.toRadians(angle)) * length) + pointA.getX(); + double yLocation = (Math.sin(Math.toRadians(angle)) * length) + pointA.getY(); + return new Point.Double(xLocation, yLocation); + } + + boolean toggleDelay = true; + + private void slowMotion() { + + if (toggleDelay) + { + try { + Thread.sleep(5); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + //toggleDelay = !toggleDelay; + } +} diff --git a/src/Tree/Branch.java b/src/Tree/Branch.java deleted file mode 100644 index 69ad775..0000000 --- a/src/Tree/Branch.java +++ /dev/null @@ -1,62 +0,0 @@ -package Tree; - -import java.awt.Color; -import java.awt.geom.Line2D; -import java.util.ArrayList; - -public class Branch { - protected Branch leftChild = null; - protected Branch rightChild = null; - protected Line2D trunk = null; - protected Color color = null; - protected int generation = 0; - - /** - * Needs development: Why use this? It can be changed to going - * down the tree. - * This array is used because of a design constraint. The tree is - * drawn by ancestry generation, meaning that parents are drawn first, - * and then its children. BUT, not in a recursive manner. One branch - * splits into two branches, those two branches split into four branches. - * Those four into eight, and so on. The tree is drawn as was just - * described. - *
Wait? if you set the array to hold 10, doesn't that set the - * total number of generation to 10? Something funny is happening here. - */ - private static ArrayList[] lines = new ArrayList[10]; - - /** - * This is the branch generator class. It is in charge of creating a branch. - * Because each branch has two children it creates a tree like behavior - * @param line A branch is simply just a line with color to it. - * @param color Sets the color of the branch - * @param generation Gives the ancestry generation to the branch - */ - Branch(Line2D line, Color color, int generation) { - this.trunk = line; - this.color = color; - this.generation = generation; - this.leftChild = null; - this.rightChild = null; - if (lines[generation-1] == null) - { - lines[generation-1] = new ArrayList(); - } - lines[generation-1].add(this); - } - - /** - * @param childBranch1 adds the left child to the parent branch - * @param childBranch2 adds the right child to the parent branch - * @param defaultForNow sets the color of the branch - * @param generation sets the generation of the branch - */ - public void createChildren(Line2D childBranch1, Line2D childBranch2, Color defaultForNow, int generation) { - leftChild = new Branch(childBranch1, defaultForNow, generation); - rightChild = new Branch(childBranch2, defaultForNow, generation); - } - public static ArrayList getListOfGenerationN(int N) - { - return lines[N-1]; - } -} diff --git a/src/Tree/Paint.java b/src/Tree/Paint.java deleted file mode 100644 index c659478..0000000 --- a/src/Tree/Paint.java +++ /dev/null @@ -1,62 +0,0 @@ -package Tree; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.util.ArrayList; -import javax.swing.JComponent; -import java.awt.geom.Ellipse2D; -import java.awt.geom.Line2D; -import java.awt.geom.Point2D; - -@SuppressWarnings("serial") -public class Paint extends JComponent { - - private static ArrayList lines = new ArrayList(); - private static ArrayList circles = new ArrayList(); - private static ArrayList circleColors = new ArrayList(); - private static ArrayList lineColors = new ArrayList(); - private static Color defaultColor = new Color(165, 42, 42); - private static BasicStroke defaulltStrokeWidth = new BasicStroke(3); - - public void paintComponent(Graphics g) { - Graphics2D g2 = (Graphics2D) g; - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - - for (int line = 0; line < lines.size(); line++) { - g2.setColor(defaultColor); - if (lineColors.get(line) != null) { - g2.setColor(lineColors.get(line)); - } - g2.setStroke(defaulltStrokeWidth); - g2.draw(lines.get(line)); - } - - for (int circle = 0; circle < circles.size(); circle++) { - g2.setColor(circleColors.get(circle)); - g2.fill(circles.get(circle)); - } - - } - - protected void addBranches(ArrayList branches) { - for (int i = 0; i < branches.size(); i++) { - lines.add(branches.get(i).trunk); - lineColors.add(branches.get(i).color); - } - } - - protected void addLine(Line2D line, Color color) { - lines.add(line); - lineColors.add(color); - } - - - protected void addCircle(Point2D point2d, Color color) { - circles.add(new Ellipse2D.Double(point2d.getX() - 5, point2d.getY() - 5, 10, 10)); - circleColors.add(color); - } -} diff --git a/src/Tree/Tree.java b/src/Tree/Tree.java deleted file mode 100644 index b963f5e..0000000 --- a/src/Tree/Tree.java +++ /dev/null @@ -1,381 +0,0 @@ -package Tree; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Point; -import java.awt.Toolkit; -import java.awt.geom.Line2D; -import java.awt.geom.Point2D; -import java.util.ArrayList; -import java.util.Random; - -import javax.swing.JFrame; - -/** - * This class takes the usage of the JFrame, and the Graphics2D libraries. - * This class will enable user to draw trees as they wish. The class takes - * advantage of the fact that each branch can be split into two other child - * branches and so on. - *
How to use: - *
You must always call one of the constructors {@link #Tree(int)}, {@link #Tree(int, Color)} - *
Then you can custumize the tree as you like it using the setters methods: - *
{@link #setSize(int)} - *
{@link #setTreeAngle(int)} - *
{@link #setSeparationAngle(int)} - *
{@link #setPositionY(int)} - *
{@link #setPositionX(int)} - *
After all is that set, call the {@link #draw(boolean)} method. - * @author Michael Santana - * @see AVL Trees - * @see JFrame - */ -public class Tree { - private static Branch root = null; - private static Color defaultColor = new Color(126, 56, 200); - private Color desiredColor = null; - private static Paint paint = new Paint(); //are multiple instances created? no - private Random random = new Random(); - private static JFrame frame; - private int limit; - private boolean drawn = false; - private int decreaseFactor = 10; - private int separationAngle = 30; // measured in degrees - private int treeAngle = 90; - private int rootPositionX = 400; - private int rootPositionY = 400; - private int faster = 115; - private static Dimension screenSize; - - /** - * @param limit This parameter determines the maximum possible ancestry length. - *
Each branch color will be selected at random - */ - Tree(int limit) - { - screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - rootPositionX = screenSize.width/2; - rootPositionY = (5*screenSize.height)/6; - initFrame(); - this.limit = limit; -// delay(1000); - } - - /** - * @param limit This parameter determines the maximum possible ancestry length - * @param color determines the color of the whole tree. If null, or otherwise - * not passed in, each branch color will be selected at random - */ - Tree(int limit, Color color) - { - this(limit); - desiredColor = color; - } - - /** - * @param safety when true, this will resize the tree to be proportional - * to your screen when the tree is going outside of your screen. Otherwise, - * the tree is drawn as is. - */ - public void draw(boolean safety) - { - if (!drawn) - { - drawn = true; - if (safety && - (decreaseFactor * 52 >= screenSize.height || - rootPositionY < (decreaseFactor * 52))) - { - setSize(screenSize.height/52); - rootPositionY = screenSize.height; - treeAngle = 90; - rootPositionX = screenSize.width/2; - } - generateTree(null, 1, limit, true); - drawTree(); - } - } - - /** - * @param positionX sets the X position of the root branch. This is based on - * the pixels on your screen, 0 being the left side of your screen, and - * increasing in value as you move to the right of your screen. - *
Note: this setting might be overwritten if the safety is on. - */ - public void setPositionX(int positionX) - { - this.rootPositionX = positionX; - } - - /** - * @param positionY sets the Y position of the root branch. This is based on - * the pixels on your screen, 0 being the top side of your screen, and - * increasing in value as you move downward on your screen. - *
Note: this setting might be overwritten if the safety is on. - */ - public void setPositionY(int positionY) - { - this.rootPositionY = positionY; - } - - /** - * @param angle the angle the root tree is facing. Angle is in measures of degrees. - * Degree 0 is to the right of the screen, 90 is vertical. - * Degree rotates in a counterclockwise motion. - */ - public void setTreeAngle(int angle) - { - this.treeAngle = angle; - } - - /** - * @param angle sets the separation between the center of two child branches. - *
Note: this setting might be overwritten if the safety is on. - */ - public void setSeparationAngle(int angle) - { - // further development: determine what is a good range to stop user from crashing code - this.separationAngle = angle; - } - - /** - * @param angle sets how big the tree should be displayed. - *
Note: this setting might be overwritten if the safety is on. - */ - public void setSize(int size) - { - // further development: determine what is a good range to stop user from crashing code - this.decreaseFactor = size; - } - - /** - * This is a recursive method that takes information of a tree and generates it - * @param currentBranch Previous branch. Initially it must be NULL. - * @param currentGen The current generation of the branch - * @param limit The limit to the number of generations. - * @param color sets the color for the entire tree. if null, then it is randomly generated. - * @return Returns a generated tree in terms of the root branch - */ - private Branch generateTree(Branch currentBranch, int currentGen, int limit, boolean debugging) { - if (desiredColor == null) - { - defaultColor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)); - } - else - { - defaultColor = desiredColor; - } - if (currentBranch == null) { - currentBranch = new Branch(makeRoot(treeAngle, rootPositionX, rootPositionY, decreaseFactor*10), defaultColor, currentGen); - root = currentBranch; - } - if (getDistanceOfLine(currentBranch.trunk) <= decreaseFactor || currentGen == limit) { - return null; - } - Point.Double endPoint = getPointB(toLineAngle(currentBranch.trunk, 180 - separationAngle), currentBranch.trunk.getP2(), getDistanceOfLine(currentBranch.trunk) - decreaseFactor); - Line2D branchLine = new Line2D.Double(currentBranch.trunk.getX2(), currentBranch.trunk.getY2(), endPoint.getX(),endPoint.getY()); - endPoint = getPointB(toLineAngle(currentBranch.trunk, 180 + separationAngle ), currentBranch.trunk.getP2(), getDistanceOfLine(currentBranch.trunk) - decreaseFactor); - Line2D branchLine2 = new Line2D.Double(currentBranch.trunk.getX2(), currentBranch.trunk.getY2(), endPoint.getX(), endPoint.getY()); - - currentBranch.createChildren(branchLine, branchLine2, defaultColor, currentGen); - currentGen++; - generateTree(currentBranch.leftChild, currentGen, limit, debugging); - generateTree(currentBranch.rightChild, currentGen, limit, false); - - return root; - } - - /** - * initializes a frame. This frame is used to paint the tree. - * If this function prevents accidentally calling it twice - * by simply returning when that happens. This function - * has some hard coded parameters such as the size of the frame - * that can be reviewed later on. - */ - private void initFrame() { - if (frame != null) { - return; // Can't create more than one instance of frame - } - Color background = new Color(200, 216, 200); - frame = new JFrame(); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setResizable(false); - frame.setMinimumSize(new Dimension(800, 600)); // default size - frame.setTitle("Tree"); - frame.getContentPane().setBackground(background); - frame.setExtendedState(JFrame.MAXIMIZED_BOTH); - frame.setUndecorated(true); - frame.setVisible(true); - frame.add(paint); - frame.setEnabled(true); - } - /** - * @param angle the angle the root tree is facing. Angle is in measures of degrees. - * Degree 0 is to the right of the screen and increases in a counterclockwise motion. - * @param x_pos The x position of the screen of where the root should be drawn - * @param y_pos The y position of the screen of where the root should be drawn - * @param length the length of the root. - * *Warning* Each successive branch is shortened at a constant rate, so - * the longer the length of the root the longer and wider the tree. To prevent creating excessively giant trees, - * either keep the length to a small size or set a reasonable limit in the constructor method - * @return Creates and returns the line of a root of a tree. - */ - private Line2D makeRoot(double angle, int x_pos, int y_pos, double length) { - Point.Double pointA = new Point.Double(x_pos, y_pos); - Point2D pointB = getPointB(angle - 180, pointA, length); - return new Line2D.Double(pointA.getX(), pointA.getY(), pointB.getX(), pointB.getY()); - } - - /** - * This method calculates the end point of a line given the beginning point of the line, - * the angle of the line, and the length of the line. - * @param angle Angle of the line - * @param beginningPoint the beginning point of the line - * @param length The length of the line. - * @return end point of a line. - */ - private Point.Double getPointB(double angle, Point2D beginningPoint, double length) { - double xLocation = (-Math.cos(Math.toRadians(angle)) * length) + beginningPoint.getX(); - double yLocation = (Math.sin(Math.toRadians(angle)) * length) + beginningPoint.getY(); - return new Point.Double(xLocation, yLocation); - } - - /** - * @param line A valid line Line2D. - * @return Returns the length of the line using the distance formula. - */ - private double getDistanceOfLine(Line2D line) { - Point2D pointA = line.getP1(); - Point2D pointB = line.getP2(); - - return Math.abs(Math.sqrt(Math.pow(pointB.getX() - pointA.getX(), 2) + Math.pow(pointB.getY() - pointA.getY(), 2))); - } - - /** - * This method calculates the new angle of a new line - * by finding the angle of the given line in addition to - * the offset angle. - * @param line A valid Line2D line. - * @param offsetAngle - * @return Returns the new angle of a new line - */ - private double toLineAngle(Line2D line, double offsetAngle) { - return getAngle(line) + offsetAngle; - } - - /** - * This method calculates the angle of a given line. - * @param line A valid Line2D line. - * @return Returns the angle of the given line - */ - private double getAngle(Line2D line) { - double height = line.getY1() - line.getY2(); - double width = line.getX2() - line.getX1(); - double angle = Math.toDegrees(Math.atan2(height, width)); - return angle; - } - - /** - * @return Returns the number of generations of a tree. - */ - private int getNumberOfGeneration() { - Branch temp = root; - int i = 0; - while (temp != null) { - temp = temp.leftChild; - i++; - } - return i; - } - - /** - * This method creates a list of Branches of a given generation N - * @param N the generation which to find in the tree. - * @return - */ - private ArrayList getListOfGenerationN(int N) { - ArrayList branches = new ArrayList(); - getListOfGenerationRcursively(root, branches, N); - return branches; - } - - /** - * This method recursively adds branches of a given generation to a list of branches. - * @param currentBranch the recursive branch. - * @param branches a valid list of branches - * @param N the generation which to find in the tree. - * @return - */ - private ArrayList getListOfGenerationRcursively(Branch currentBranch, ArrayList branches, int N) { - if (currentBranch == null) { - return null; - } - if (currentBranch.generation == N) { - branches.add(currentBranch); - } - getListOfGenerationRcursively(currentBranch.leftChild, branches, N); - getListOfGenerationRcursively(currentBranch.rightChild, branches, N); - return branches; - } - - /** - * This draws the tree. - *
If the safety is on, the tree will be set to optimal settings. - *
This method draws the tree in slow motion. - */ - private void drawTree() { - int i = 0; - int genNum = getNumberOfGeneration(); - for (i = 1; i < genNum; i++) { - paint.addBranches(Branch.getListOfGenerationN(i)); - paint.repaint(); -// delay(20); - slowMotion(); - } - if (desiredColor == null) { - for (int n = 0; n < getListOfGenerationN(i-1).size(); n++) { - paint.addCircle(getListOfGenerationN(i-1).get(n).trunk.getP2(), - new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256))); - paint.repaint(); - } - } - else { - for (int n = 0; n < getListOfGenerationN(i-1).size(); n++) { - paint.addCircle(getListOfGenerationN(i-1).get(n).trunk.getP2(), - desiredColor); - paint.repaint(); - } - } - } - - /** - * This method slows down the drawing process by putting the thread to sleep. - * This is used for aesthetics. - */ - private void slowMotion() { - try { - Thread.sleep(faster); - } catch (InterruptedException e) { - e.printStackTrace(); - } - faster = faster - 10; - if (faster < 0) { - faster = 0; - } - } - /** - * This method slows down the drawing process by putting the thread to sleep. - * This is used for aesthetics. - */ - @SuppressWarnings("unused") - private void delay(long delay) - { - try - { - Thread.sleep(delay); - } - catch(InterruptedException ex) - { - Thread.currentThread().interrupt(); - } - } -} \ No newline at end of file diff --git a/src/Tree/TreeMain.java b/src/Tree/TreeMain.java deleted file mode 100644 index 42f6fb4..0000000 --- a/src/Tree/TreeMain.java +++ /dev/null @@ -1,20 +0,0 @@ -package Tree; - -import java.awt.Color; - -public class TreeMain { - - public static void main(String[] args) { - drawToDegree(30, 1000, 800, 100, null,10, true); - } - public static void drawToDegree(int degree, int x, int y, int size, Color color, int limit, boolean safety) - { - Tree tree = new Tree(limit, color); - tree.setSize(size); - tree.setTreeAngle(90); - tree.setSeparationAngle(degree); - tree.setPositionY(y); - tree.setPositionX(x); - tree.draw(safety); - } -}