From d18676fbf6969b2b7414ecc3114146c35d09e5f3 Mon Sep 17 00:00:00 2001 From: Fr3deric Date: Sat, 9 Mar 2019 23:53:30 +0100 Subject: [PATCH] fill crowns with a pattern --- baumgen.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/baumgen.js b/baumgen.js index afc1c2c..8ee676c 100644 --- a/baumgen.js +++ b/baumgen.js @@ -67,6 +67,54 @@ function gen_tree(pos, maxheight) { } +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: false}); + pp.strokeWidth = 1.5; + pp.strokeColor = 'black'; + } + + if(typeof branch.forks !== "undefined") { + for(let fork of branch.forks) { + this.apply(fork.branch); + } + } + } +} + + +class HatPattern extends Pattern { + constructor({tasize=7, grid=17}={}) + { + super('hat') + this.tasize = tasize; + this.grid = grid; + } + + generate(bounds) { + var ret = []; + for(var y=0; y