Skip to content

Commit 79db066

Browse files
author
idlework
committed
minor changes to the code and some nice tree screenshots
1 parent 970a6a8 commit 79db066

10 files changed

+28
-23
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ application.linux64
55
application.windows32
66
application.windows64
77
application.macosx
8+
9+
build-tmp/

GenerativeTree.pde

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

7475
class 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

113116
class Leaf {
114-
int[] colors = {#cc0000, #c00000, #cf0000, #d50000, #da0000, #da0000};
117+
int[] colors = {#CC0000, #C00000, #CF0000, #D50000, #DA0000, #DA0000};
115118

116119
PVector position;
117120

22.8 KB
Loading
28.9 KB
Loading
85.7 KB
Loading
30.6 KB
Loading
55.2 KB
Loading

screenshots/tree_20150314_3132.png

27.5 KB
Loading

screenshots/tree_20150314_6273.png

36.4 KB
Loading

screenshots/tree_20150314_7800.png

37.5 KB
Loading

0 commit comments

Comments
 (0)