|
|
|
@ -2,26 +2,26 @@
@@ -2,26 +2,26 @@
|
|
|
|
|
paper.install(window); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function gen_tree(pos) { |
|
|
|
|
function gen_tree(pos, maxheight) { |
|
|
|
|
var baum = new Branch(); |
|
|
|
|
|
|
|
|
|
baum.length = (20 + Math.random() * 20); |
|
|
|
|
baum.length = 0.15 * maxheight + 0.15 * maxheight * Math.random(); |
|
|
|
|
|
|
|
|
|
var shapernd = Math.random() * 3; |
|
|
|
|
if(shapernd < 1) { |
|
|
|
|
baum.crown = new KiteCrown( |
|
|
|
|
70 + Math.random() * 30, |
|
|
|
|
0.49 * maxheight + 0.21 * maxheight * Math.random(), |
|
|
|
|
0.4 + Math.random() * 0.2, |
|
|
|
|
{bisect: 0.2 + Math.random() * 0.2}, |
|
|
|
|
); |
|
|
|
|
} else if(shapernd < 2) { |
|
|
|
|
baum.crown = new TriangleCrown( |
|
|
|
|
70 + Math.random() * 30, |
|
|
|
|
0.49 * maxheight + 0.21 * maxheight * Math.random(), |
|
|
|
|
0.4 + Math.random() * 0.2, |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
baum.crown = new EllipseCrown( |
|
|
|
|
70 + Math.random() * 30, |
|
|
|
|
0.49 * maxheight + 0.21 * maxheight * Math.random(), |
|
|
|
|
0.4 + Math.random() * 0.2, |
|
|
|
|
{bisect: 0.1 + Math.random() * 0.4}, |
|
|
|
|
); |
|
|
|
@ -80,6 +80,10 @@ class Crown {
@@ -80,6 +80,10 @@ class Crown {
|
|
|
|
|
collides(other) { |
|
|
|
|
return this._path.intersects(other._path); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
get bounds() { |
|
|
|
|
return this._path.bounds; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -220,6 +224,24 @@ class Branch {
@@ -220,6 +224,24 @@ class Branch {
|
|
|
|
|
collides_crown(other) { |
|
|
|
|
return this.crown.collides(other.crown); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
get bounds() { |
|
|
|
|
var b = this._branch.bounds; |
|
|
|
|
b = b.unite(this.crown.bounds); |
|
|
|
|
if(typeof this.forks !== "undefined") { |
|
|
|
|
for (let fork of this.forks) { |
|
|
|
|
b = b.unite(fork.branch.bounds); |
|
|
|
|
/* |
|
|
|
|
var r = new Path.Rectangle({ |
|
|
|
|
point: fork.branch.bounds.point, |
|
|
|
|
size: fork.branch.bounds.size, |
|
|
|
|
strokeWidth: 1, |
|
|
|
|
strokeColor: 'green'}); |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return b; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -227,11 +249,38 @@ function draw() {
@@ -227,11 +249,38 @@ function draw() {
|
|
|
|
|
var canvas = document.getElementById('canvas'); |
|
|
|
|
paper.setup(canvas); |
|
|
|
|
|
|
|
|
|
//var br = new Branch(baum);
|
|
|
|
|
|
|
|
|
|
for(var x=0; x<10; x++) { |
|
|
|
|
for(var y=0; y<5; y++) { |
|
|
|
|
var br = new Branch(gen_tree(new Point(50 + x*80, 150 + y*160))); |
|
|
|
|
var width = 148 * 5; |
|
|
|
|
var height = 105 * 5; |
|
|
|
|
var rows = 3; |
|
|
|
|
var rowspace = 20; |
|
|
|
|
var inspace = 30; |
|
|
|
|
var outspace = 10; |
|
|
|
|
|
|
|
|
|
var maxh = (height - (rows-1)*rowspace - 2*outspace - 2*inspace) / rows; |
|
|
|
|
|
|
|
|
|
var outline = new Path.Rectangle({ |
|
|
|
|
point: new Point(outspace, outspace), |
|
|
|
|
size: new Size(width - 2*outspace, height - 2*outspace), |
|
|
|
|
strokeWidth: 2, |
|
|
|
|
strokeColor: 'black' |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
for(var row=0; row<rows; row++) { |
|
|
|
|
var y = outspace + inspace + maxh * (row + 1) + rowspace * row; |
|
|
|
|
var x = outspace + inspace + 20; // TODO approx width
|
|
|
|
|
var prev; |
|
|
|
|
while(x < width - outspace - inspace - 60) { // TODO approx width
|
|
|
|
|
var yy = y + Math.random() * 40 - 20; |
|
|
|
|
x += Math.random() * 10; // TODO approx width
|
|
|
|
|
var t = gen_tree(new Point(x, yy), maxh); |
|
|
|
|
if(typeof prev !== 'undefined') { |
|
|
|
|
while(prev.bounds.intersects(t.bounds)) { |
|
|
|
|
x += 15; |
|
|
|
|
t.draw(new Point(x, y)); |
|
|
|
|
console.log('intersects'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
prev = t; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|