|
|
|
@ -75,7 +75,7 @@ class Pattern {
@@ -75,7 +75,7 @@ class Pattern {
|
|
|
|
|
apply(branch) { |
|
|
|
|
var crownpath = branch.crown._path; |
|
|
|
|
for (let p of this.generate(crownpath.bounds)) { |
|
|
|
|
var pp = p.intersect(crownpath, {trace: false}); |
|
|
|
|
var pp = p.intersect(crownpath, {trace: this._intersect_trace}); |
|
|
|
|
pp.strokeWidth = 1.5; |
|
|
|
|
pp.strokeColor = 'black'; |
|
|
|
|
} |
|
|
|
@ -89,12 +89,14 @@ class Pattern {
@@ -89,12 +89,14 @@ class Pattern {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HatPattern extends Pattern { |
|
|
|
|
constructor({tasize=7, grid=17}={}) |
|
|
|
|
class MiniLinePattern extends Pattern { |
|
|
|
|
constructor({tasize=7, grid=17, hat=true}={}) |
|
|
|
|
{ |
|
|
|
|
super('hat') |
|
|
|
|
this.tasize = tasize; |
|
|
|
|
this.grid = grid; |
|
|
|
|
this.hat = hat; |
|
|
|
|
this._intersect_trace = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
generate(bounds) { |
|
|
|
@ -105,7 +107,9 @@ class HatPattern extends Pattern {
@@ -105,7 +107,9 @@ class HatPattern extends Pattern {
|
|
|
|
|
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)); |
|
|
|
|
if(this.hat) { |
|
|
|
|
p.add(new Point(xx + this.tasize/2, yy)); |
|
|
|
|
} |
|
|
|
|
p.add(new Point(xx + this.tasize, yy+this.tasize)); |
|
|
|
|
ret.push(p); |
|
|
|
|
} |
|
|
|
@ -114,6 +118,33 @@ class HatPattern extends Pattern {
@@ -114,6 +118,33 @@ class HatPattern extends Pattern {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class RandomCirclePattern extends Pattern { |
|
|
|
|
constructor({radius=3, grid=15}={}) |
|
|
|
|
{ |
|
|
|
|
super('hat') |
|
|
|
|
this.radius = radius; |
|
|
|
|
this.grid = grid; |
|
|
|
|
this._intersect_trace = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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 + Math.random() * this.grid/2; |
|
|
|
|
var yy = bounds.y + y*this.grid + Math.random() * this.grid/2; |
|
|
|
|
var p = new Path.Circle({ |
|
|
|
|
center: new Point(xx, yy), |
|
|
|
|
radius: this.radius |
|
|
|
|
}); |
|
|
|
|
ret.push(p); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Crown { |
|
|
|
|
constructor(length, width, shape) { |
|
|
|
@ -336,8 +367,20 @@ function draw() {
@@ -336,8 +367,20 @@ function draw() {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var ptrn = new HatPattern(); |
|
|
|
|
ptrn.apply(t); |
|
|
|
|
var ptrn = null; |
|
|
|
|
var ptrnrand = Math.random() * 5; |
|
|
|
|
if(ptrnrand < 1) { |
|
|
|
|
ptrn = new MiniLinePattern(); |
|
|
|
|
} else if(ptrnrand < 2) { |
|
|
|
|
ptrn = new MiniLinePattern({hat: false}); |
|
|
|
|
} else if(ptrnrand < 3) { |
|
|
|
|
ptrn = new RandomCirclePattern(); |
|
|
|
|
} else if(ptrnrand < 4) { |
|
|
|
|
ptrn = new RandomCirclePattern({radius: 1}); |
|
|
|
|
} |
|
|
|
|
if(ptrn != null) { |
|
|
|
|
ptrn.apply(t); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
prev = t; |
|
|
|
|
} |
|
|
|
|