Tree
https://gyazo.com/cde23c454f322e4c67fd04f932e2f0b1
code:java
int _numChildren = 3;
int _maxLevels = 3;
Branch _trunk;
void setup() {
size(750, 500);
background(255);
noFill();
smooth();
newTree();
}
void newTree() {
_trunk = new Branch(1, 0, width/2, 50);
_trunk.drawMe();
}
class Branch {
float level, index;
float x, y;
float endx, endy;
Branch [] children = new Branch0; Branch(float lev, float ind, float ex, float why) {
level = lev;
index = ind;
updateMe(ex, why);
if (level < _maxLevels) {
for (int x = 0; x < _numChildren; x++) {
childrenx = new Branch(level+1, x, endx, endy); }
}
}
void updateMe(float ex, float why) {
x = ex;
y = why;
endx = x + (level * (random(100) - 50));
endy = y + 50 + (level * random(50));
}
void drawMe() {
strokeWeight(_maxLevels - level + 1);
line(x, y, endx, endy);
ellipse(x, y, 5, 5);
for (int i = 0; i < children.length; i++) {
}
saveFrame("####.jpg");
}
}