@@ -40,35 +40,36 @@ class Tree {
4040 }
4141
4242 void draw () {
43- Branch branch;
44- boolean divaricate;
45-
4643 for (int i = 0 ; i < branches. size(); i++ ) {
47- branch = branches. get(i);
48- branch. draw();
49- divaricate = Math . round(Math . random() * (branch. thickness / 2 )) == 1 ;
50-
51- if (divaricate) {
52- double angle = branch. angle + ((Math . random() - .5 ) * 2 );
53- float thickness = random (1 , branch. thickness);
54- createBranch(branch. position, angle, thickness);
55- }
56-
57- if (branch. thickness < 7 ) {
58- Leaf leaf = new Leaf (branch. position. get());
59- leaf. draw();
60- }
61-
62- if (branch. ended) {
63- branches. remove(branch);
64- }
44+ updateBranch(branches. get(i));
6545 }
6646 }
6747
6848 void createBranch (PVector position , double angle , float thickness ) {
6949 Branch branch = new Branch (position, angle, thickness);
7050 branches. add(branch);
7151 }
52+
53+ void updateBranch (Branch branch ) {
54+ branch. draw();
55+
56+ boolean divaricate = Math . round(Math . random() * (branch. thickness / 2 )) == 1 ;
57+
58+ if (divaricate) {
59+ double angle = branch. angle + ((Math . random() - .5 ) * 2 );
60+ float thickness = random (1 , branch. thickness);
61+ createBranch(branch. position, angle, thickness);
62+ }
63+
64+ if (branch. thickness < 7 ) {
65+ Leaf leaf = new Leaf (branch. position. get());
66+ leaf. draw();
67+ }
68+
69+ if (branch. ended) {
70+ branches. remove(branch);
71+ }
72+ }
7273}
7374
7475class Branch {
@@ -96,7 +97,9 @@ class Branch {
9697 strokeWeight (thickness);
9798
9899 double length = (Math . random() * 8 ) + 4 ;
99- angle += Math . PI / 180 * ((Math . random() * 30 ) - 15 );
100+ angle += PI / 180 * ((Math . random() * 30 ) - 15 );
101+
102+ println (PI / 180 );
100103
101104 PVector newPosition = position. get();
102105 newPosition. x += length * Math . cos(angle);
@@ -111,7 +114,7 @@ class Branch {
111114}
112115
113116class Leaf {
114- int [] colors = {#cc0000 , #c00000 , #cf0000 , #d50000 , #da0000 , #da0000 };
117+ int [] colors = {#CC0000 , #C00000 , #CF0000 , #D50000 , #DA0000 , #DA0000 };
115118
116119 PVector position;
117120
0 commit comments