Tree = {class Tree{
constructor(root_x,
root_y,
root_r,
root_a,
one,
stepsize,
branch_split_angle,
branch_prob_scale,
branch_diminish,
branch_split_diminish,
branch_angle_max,
branch_angle_exp) {
this.root_x = root_x
this.root_y = root_y
this.root_r = root_r
this.root_a = root_a
this.stepsize = stepsize
this.one = one
this.branch_split_angle = branch_split_angle
this.branch_diminish = branch_diminish
this.branch_split_diminish = branch_split_diminish
this.branch_angle_max = branch_angle_max
this.branch_angle_exp = branch_angle_exp
this.branch_prob_scale = branch_prob_scale
this.init()
}
init(){
this.Q = []
const branch = new Branch(this,
this.root_x,
this.root_y,
this.root_r,
this.root_a,
0)
this.Q.push(branch)
}
step(){
const q_remove = []
const q_new = []
this.Q.forEach((b, i)=>{
b.step()
if(b.r<=this.one){
q_remove.push(i)
}
const branch_prob = (this.root_r-b.r+this.one)*this.branch_prob_scale;
if(Math.random()<branch_prob){
const x = b.x
const y = b.y
const a = b.a
const r = b.r
const g = b.g
const new_r = this.branch_split_diminish*r
const ra = ((-1)**Math.floor(Math.random()*2))*Math.random()*this.branch_split_angle
q_new.push(new Branch(this,
x,
y,
new_r,
a + ra,
g+1))
} else {
q_remove.push(i)
q_new.push(b)
}
});
this.Q = this.Q.filter((_, idx)=>!q_remove.includes(idx));
this.Q = [...this.Q, ...q_new];
}
};
return Tree;
}