-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFractalTree3.java
More file actions
36 lines (33 loc) · 826 Bytes
/
FractalTree3.java
File metadata and controls
36 lines (33 loc) · 826 Bytes
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
public class FractalTree3 {
public static void main(String[] args) {
Turtle t = new Turtle();
t.delay(0);
t.left(90);
tree(t, 150, 20);
}
public static void tree(Turtle t, double size, int level) {
int red = (int)(Math.random() * 256);
int green = (int)(Math.random() * 256);
int blue = (int)(Math.random() * 256);
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(45);
tree(t, size * 0.8, level - 1);
// second branch
t.right(90);
tree(t, size * 0.6, level - 1);
t.left(45);
t.penup();
t.backward(size);
t.pendown();
}
}
}