java tree fractals
TRANSCRIPT
Tree Fractals
The Walker School
APCSA
1
2
What is a Fractal?
• Geometric object
• Self-similar across scale
• The exhibit roughness
• Recursive definition
3
Fractal Geometry
• Infinite + finite
• Simple becomes complex
Where do we find fractals in nature?
Everywhere!
Tree Fractals
6
7
1 + 2(1/2) + 4(1/4) + 8(1/8) + ... = ∞
Length: 1
Length: 0.5
Infinite length in a finite area!
8
…
Simple process
Complex result
9
Recursive Definition
• Define something in terms of itself
• Tree: a trunk with two subtrees at the top
10
Designing recursion requires...
Assumption(Leap of Faith)
Pseudocode Algorithm
• Draw the trunk
• Draw the two subtrees
• Go back to the base of the trunk
11
Pseudocode Algorithm
• Draw the trunk
• Draw the two subtrees
• Go back to the base of the trunk
12
Java Code
• A method that calls itself
• How to stop from going forever?
13
Java Code
• Base case
• Recursion “bottoms out”
• Must use arguments to manage this
14
Better Pseudocode
• To draw a tree of depth n and trunk size x:
–if depth is 1:
•Draw a trunk of length x
–else:
•Draw a trunk of length x
•Draw two trees of depth (n-1) and trunk size (x/2)
–Go back to the base of the trunk
15
Basic Tree
16
Unit Circle
0
-90
90
180
X
Y sinθ = y/1 = y
cosθ = x/1 = x
(x,y)(x,y)
Recursive Method
Method Call
Angles and Length
19
Colors
20
Forests
21
What else?
22
Examples for Inspiration
23
Golden Ratio Tree Fractal
https://www.behance.net/gallery/720515/Worlds-Largest-Fractal-Vectors
Pythagorean Tree
https://www.behance.net/gallery/720515/Worlds-Largest-Fractal-Vectors
Fractal Branching Tree
https://www.behance.net/gallery/720515/Worlds-Largest-Fractal-Vectors
Contact
If you want the Java code for some of the basic trees you can contact me at:
Thomas Cooper
The Walker School
Marietta, GA 30062
Website: http://www.thewalkerschool.org
Email: [email protected]