paper.install(window); function gen_tree(pos, maxheight) { var baum = new Branch(); baum.length = 0.15 * maxheight + 0.15 * maxheight * Math.random(); var shapernd = Math.random() * 3; if(shapernd < 1) { baum.crown = new KiteCrown( 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( 0.49 * maxheight + 0.21 * maxheight * Math.random(), 0.4 + Math.random() * 0.2, ); } else { baum.crown = new EllipseCrown( 0.49 * maxheight + 0.21 * maxheight * Math.random(), 0.4 + Math.random() * 0.2, {bisect: 0.1 + Math.random() * 0.4}, ); } baum.angle = Math.PI / 2; if(Math.random() < 0.3) { baum.angle += Math.random() * 0.2 - 0.1; } if((baum.crown.shape != "triangle") && (Math.random() < 0.5)) { var b = { length: baum.length * 0.4, angle: Math.PI / 2, crown: baum.crown.clone() }; b.crown.length *= 0.4; b.crown.width = 0.8; baum.forks = [{ pos: 0.2 + Math.random() * 0.4, branch: new Branch(b), }]; baum.draw(pos); var step = (Math.random() < 0.5) ? -0.1 : 0.1; while(baum.collides_crown(baum.forks[0].branch)) { baum.forks[0].branch.angle += step; 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); return baum; } class Pattern { constructor(type) { this.type = type; } apply(branch) { var crownpath = branch.crown._path; for (let p of this.generate(crownpath.bounds)) { var pp = p.intersect(crownpath, {trace: this._intersect_trace}); pp.strokeWidth = 1.5; pp.strokeColor = 'black'; } if(typeof branch.forks !== "undefined") { for(let fork of branch.forks) { this.apply(fork.branch); } } } } class MiniLinePattern extends Pattern { constructor({tasize=7, grid=17, hat=true}={}) { super('miniline') this.tasize = tasize; this.grid = grid; this.hat = hat; this._intersect_trace = false; } generate(bounds) { var ret = []; for(var y=0; y