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