|
|
|
@ -67,6 +67,54 @@ function gen_tree(pos, maxheight) {
@@ -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<bounds.height / this.grid; y++) { |
|
|
|
|
for(var x=0; x<bounds.width / this.grid; x++) { |
|
|
|
|
var xx = bounds.x + x*this.grid + this.grid/3 * (y%2); |
|
|
|
|
var yy = bounds.y + y*this.grid; |
|
|
|
|
var p = new Path(); |
|
|
|
|
p.add(new Point(xx, yy+this.tasize)); |
|
|
|
|
p.add(new Point(xx + this.tasize/2, yy)); |
|
|
|
|
p.add(new Point(xx + this.tasize, yy+this.tasize)); |
|
|
|
|
ret.push(p); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Crown { |
|
|
|
|
constructor(length, width, shape) { |
|
|
|
|
this.width = width; |
|
|
|
@ -287,6 +335,10 @@ function draw() {
@@ -287,6 +335,10 @@ function draw() {
|
|
|
|
|
console.log('intersects'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var ptrn = new HatPattern(); |
|
|
|
|
ptrn.apply(t); |
|
|
|
|
|
|
|
|
|
prev = t; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|