-
Notifications
You must be signed in to change notification settings - Fork 0
/
FractalTree2.java
38 lines (36 loc) · 1.01 KB
/
FractalTree2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class FractalTree2 {
//black 0, 0, 0) and white(255, 255, 255)
public static void main(String[] args) {
Turtle t = new Turtle();
t.delay(1);
t.left(90);
tree(t, 150, 10);
}
public static void tree(Turtle t, double size, int level) {
int red = 255 - Math.min(20 * level, 255); //take smaller of the two so that number will never exceed 255, puts cap on
//as level increases, amt of red decreases
//more red at low levels (level 0 is leaves, level 10 is stem) bc work backward
int green = 0;
int blue = 0;
t.color(red, green, blue);
if (level == 0) {
t.forward(size);
t.penup();
t.backward(size);
t.pendown();
} else {
// stem
t.forward(size);
// first branch
t.left(30);
tree(t, size * 0.8, level - 1);
// second branch
t.right(30 + 45);
tree(t, size * 0.6, level - 1);
t.left(45);
t.penup();
t.backward(size);
t.pendown();
}
}
}