Browse Source

determine branch angle range before randomizing

master
Fr3deric 5 years ago
parent
commit
bc71bf0b55
  1. 29
      baumgen.js

29
baumgen.js

@ -30,37 +30,32 @@ function gen_tree(pos) { @@ -30,37 +30,32 @@ function gen_tree(pos) {
baum.angle = Math.PI / 2; // + Math.random() * 0.2 - 0.1;
if((baum.crown.shape != "triangle") && (Math.random() < 0.5)) {
var crown = baum.crown.clone();
crown.length *= 0.4;
var b = {
length: baum.length * 0.4,
angle: Math.PI / 5 + Math.random() * 0.45,
crown: crown
angle: Math.PI / 2,
crown: baum.crown.clone()
};
b.crown.length *= 0.4;
baum.forks = [{
pos: 0.2 + Math.random() * 0.4,
branch: new Branch(b),
}];
baum.draw(pos);
var rectified = false;
var i=0;
var step = (Math.random() < 0.5) ? -0.1 : 0.1;
while(baum.collides_crown(baum.forks[0].branch)) {
baum.forks[0].branch.angle -= 0.01;
baum.forks[0].branch.angle += step;
baum.draw(pos);
rectified = true;
i += 1;
if(i>50) {
var c = new Path.Circle({center:pos, radius: 2, strokeWidt: 1, strokeColor: '#ff0000'});
//break;
}
}
if(rectified) {
baum.forks[0].branch.angle -= Math.random() * 0.1;
var c = new Path.Circle({center:pos, radius: 2, strokeWidt: 1, strokeColor: '#ff0000'});
baum.draw(pos);
var range = 4*Math.PI/9 - Math.abs(Math.PI/2 - baum.forks[0].branch.angle);
if(step > 0) {
baum.forks[0].branch.angle += range * (0.1 + 0.9 * Math.random());
} else {
baum.forks[0].branch.angle -= range * (0.1 + 0.9 * Math.random());
}
baum.draw(pos);
}
baum.draw(pos);

Loading…
Cancel
Save