# "If you please, draw me a fractal tree (*)."

In this assignment you will be asked to draw a Fractal Tree. The drawing of this sort of fractal is based on recursive call to the same method. By recursion we mean something that uses itself to define itself. E.g. "GNU acronym stands for: 'GNU is Not Unix'". That first example is of course a bad hacker joke. More Seriously, you can define the mathematical value of factorial n (which is n(n-1)(n-2)... 2 * 1 ) by :

• factorial(n) = n * factorial(n -1) if n > 0
• factorial(0) = 1
• Have a look at Exercise 2 and its tips about recursion

#### Here is a general idea of such a drawing

 Or still another level...

### Here is a more precise idea of the algorithm

 Parameters a,b,c : the angle in radians between a branch and the following one. NB. : following the trigonometric convention, on this example, a and b are positive angles and c is negative. k1, k2, k3 : by how much the length of the branch is reduced at the next level. l1 = k1 * L l2 = k2 * L l3 = k3 * L m2, m3 : the factors that define the position (F and G) of the start of new sub-branches from a main one : OF = m2 * L OG = m3 * L leaf

## The process :

For each branch defined by its end point O, its length L, its direction and its level (Note that this information would perhaps be coded differently in your own program)
• If we have reached the chosen level limit of recursion or if the size of the next branch would be smaller than the chosen limit for this size, then we draw a green leaf that follows the direction of the branch.
• If not, then we draw 3 new brown branches
• The main one, connected at O to the previous branch, that form an angle a with that previous branch and whose length is k1 * L
• The first sub-branch, connected at F to the main branch, that form an angle b with that main branch and whose length is k2 * L
• The second sub-branch, connected at G to the main branch, that form an angle c with that main branch and whose length is k3 * L

## Ground Rules for all projects:

• The design and coding must be your own. There is plenty of room for originality.
• Don't use code from previous semesters.
• Should I remind you of the importance of a code well presented and documented ?
• Cite any models, images, ideas, or algorithms that you do not develop yourself.
• Project is due before midnight of the day indicated : 10th September 2002.
• Please read this text through to the end before touching any keyboard.
• Take time to think before you touch your keyboard
• Then before beginning the project, have a look at this document on the web page : you will find some useful links like the one to the README file model.

## To submit a project...

### you should put altogether, in a directory called CG_A1_02_UstudentID...

#### (Where 'studentID'...is your student ID !... CG_A1_02 means the first assignment in Computer Graphics lecture of the year 2002)

• Your well commented Java source file(s)
• The documentation generated by javadoc
• A 'README.html' HTML file that should summarise and/or describe (it is your report file and is important in the marking)...
• all that is available in your directory
• the options you have chosen to implement (there should be at least 2 of them)
• how to use your program
• the command line options
• the GUI
• The way you have implemented the algorithm (tricks that are particulars to your work)
• one or more screenshot of your program (that shows both the tree and the GUI)

Here is its README.html file template

### Use the jar command to put your directory into a single jar file based on the same name and mail this file to pascal.vuylsteker@anu.edu.au

`cd .. (go to the directory in which your CG_A1_02_UstudentID is located)`
```jar cvf CG_A1_02_UstudentID.jar CG_A1_02_UstudentID/
```

Mail the file (CG_A1_02_UstudentID.jar) as an attached document. Be sure that the title of your mail is 'CG_A1_02_UstudentID''

!!! Your jar file should not be more than 500 kB !!!

## The minimum requirements

Your project should be composed of, or respect, at least, the following :

(1) 3 different main classes (there could be of course more, but there should not be more than 15 classes for this size of project). Explain in the README file what the role of the 3 classes are.

(2) One of the classes should be a public class, whose name will be "Assignment", and will contain the "main method" in such a way that, to test your project, I will only need to call 'java Assignment [command line arguments]' to run it. Because yours classes will be well documented, I should be able to write that "Assignment" class by myself without to much work.

(3) You will explain the use of the arguments in your README file but the first two will be levelLimit sizeLimit

E.g. : java Assignment 5 10
will draw the branches up to the 5th level as long as the branch size is not smaller than 10

(4) By default, the opening window should be well positioned (you should see it entirely, but it should not use all the screen space, between half and 2/3rd of the space) whatever is the size of the screen.

(5) Remember that sometimes, users may be dumb and may not use the right number of arguments. You should deal with that sort of situation

(6) Remember that again, users may be dumb and could use a very high Iteration Number. It could be a good idea to have 2 trivial criteria to end the recursion. One is the number of iterations, the other one is...(this is the sort of thing -amongst others- that should appear either in your code comments and in the README file)

(7) One peculiarity of these fractal displays is that the panel should be resizable (whenever the size of the window is changed by the user, the fractal should be redrawn trying -it is not always possible- to fit in the available space when using the default parameters).

(8) Within the main frame or in the second one, it should be possible to change all the parameters of the tree and redraw it when wanted. It should be possible to get back to the set of default parameters that you will have established as producing a good looking tree.

(9) The tree should grow up from the bottom of your frame

(10) The compile classes should be available at the root of your directory. During the marking process, I may :

• unjar your jar file (jar xvf...)
• cd into your directory (all the file should be in your directory or in subdirectories and should not mess with my working directory !)
• run 'java Assignment 5 10'
• del *.class
• javac *.java
• and keep doing other sort of tests...

## (Not So) Optional Development:

You should do at least two of the following options to get the maximum mark

• Colour/Thickness : Use of the colour and the thickness of the drawing to make the fractal more alluring : the colour and thickness of the branch should be different regarding its age (recursive level). It sound reasonable that the stump of the tree should be the thicker and darker...
• Leaves : Let the user choose different sort of leaves (at least 3 sorts).
• Randomness : Allow the parameter to be changed slightly and randomly at each iteration. You should then allow the user to chose the range for each parameters.
• Branching : The previous process define one main branch and 2 sub-branches at each level. In that option, you should allow the user to decide the number of sub-branches and of course the matching parameters.
• Incremental drawing : By default, it is asked to draw only the final stage of the recursion, but you could add an option to draw the levels step by step.

## Penalties for late submission:

Late submission may be penalised at 10% per day late.

(*) If you didn't know that the original quotation was about a sheep, you should perhaps first read "The little prince" story before beginning to do computer graphics.

 Web www.vrarchitect.net