Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tree root;
- ArrayList<Tree> fullTree = new ArrayList<Tree>();
- void setup() {
- fullScreen();
- PVector a = new PVector(width/2, height);
- PVector b = new PVector(width/2, height - 100);
- root = new Tree(a, b, PI/10, 20);
- background(51);
- root.show();
- }
- //void draw() {
- // background(51);
- //}
- class Tree {
- private PVector start, end;
- private float angle;
- private int depth;
- private Tree left, right;
- public Tree(PVector start, PVector end, float angle, int depth) {
- this.start = start;
- this.end = end;
- this.depth = depth;
- this.angle = angle;
- if (this.depth >= 0) {
- this.left = this.branch("left");
- this.right = this.branch("right");
- }
- }
- public void show() {
- stroke(255);
- line(this.start.x, this.start.y, this.end.x, this.end.y);
- if (this.depth > 0) {
- this.left.show();
- this.right.show();
- }
- }
- public Tree branch(String direction) {
- int sign = -1;
- if (direction.equals("right")) {
- sign *= sign;
- }
- PVector dir = PVector.sub(this.end, this.start);
- dir.rotate(sign * this.angle);
- dir.mult(.82);
- PVector newEnd = PVector.add(this.end, dir);
- return new Tree(this.end, newEnd, this.angle, this.depth - 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement