Browse Source

more pattern types

master
Fr3deric 6 years ago
parent
commit
07c329b44d
  1. 51
      baumgen.js

51
baumgen.js

@ -75,7 +75,7 @@ class Pattern {
apply(branch) { apply(branch) {
var crownpath = branch.crown._path; var crownpath = branch.crown._path;
for (let p of this.generate(crownpath.bounds)) { 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.strokeWidth = 1.5;
pp.strokeColor = 'black'; pp.strokeColor = 'black';
} }
@ -89,12 +89,14 @@ class Pattern {
} }
class HatPattern extends Pattern { class MiniLinePattern extends Pattern {
constructor({tasize=7, grid=17}={}) constructor({tasize=7, grid=17, hat=true}={})
{ {
super('hat') super('hat')
this.tasize = tasize; this.tasize = tasize;
this.grid = grid; this.grid = grid;
this.hat = hat;
this._intersect_trace = false;
} }
generate(bounds) { generate(bounds) {
@ -105,7 +107,9 @@ class HatPattern extends Pattern {
var yy = bounds.y + y*this.grid; var yy = bounds.y + y*this.grid;
var p = new Path(); var p = new Path();
p.add(new Point(xx, yy+this.tasize)); p.add(new Point(xx, yy+this.tasize));
if(this.hat) {
p.add(new Point(xx + this.tasize/2, yy)); p.add(new Point(xx + this.tasize/2, yy));
}
p.add(new Point(xx + this.tasize, yy+this.tasize)); p.add(new Point(xx + this.tasize, yy+this.tasize));
ret.push(p); ret.push(p);
} }
@ -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 { class Crown {
constructor(length, width, shape) { constructor(length, width, shape) {
@ -336,8 +367,20 @@ function draw() {
} }
} }
var ptrn = new HatPattern(); 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); ptrn.apply(t);
}
prev = t; prev = t;
} }

Loading…
Cancel
Save