File size: 508 Bytes
bc20498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
export default class TreeNode {
  constructor(width, height) {
    this.width = width
    this.height = height
    this.x = 0
    this.y = 0
    this.children = []
  }

  addChild(child) {
    child.y = this.y + this.height
    this.children.push(child)
  }

  randExpand(tree) {
    tree.y += this.height
    const i = Math.floor(Math.random() * (this.children.length + 1))
    if (i === this.children.length) {
      this.children.push(tree)
    } else {
      this.children[i].randExpand(tree)
    }
  }
}