Browse Source

add line pattern

master
Fr3deric 6 years ago
parent
commit
ee2ceff56b
  1. 37
      baumgen.js

37
baumgen.js

@ -92,7 +92,7 @@ class Pattern { @@ -92,7 +92,7 @@ class Pattern {
class MiniLinePattern extends Pattern {
constructor({tasize=7, grid=17, hat=true}={})
{
super('hat')
super('miniline')
this.tasize = tasize;
this.grid = grid;
this.hat = hat;
@ -121,7 +121,7 @@ class MiniLinePattern extends Pattern { @@ -121,7 +121,7 @@ class MiniLinePattern extends Pattern {
class RandomCirclePattern extends Pattern {
constructor({radius=3, grid=15}={})
{
super('hat')
super('randomcircle')
this.radius = radius;
this.grid = grid;
this._intersect_trace = true;
@ -145,6 +145,35 @@ class RandomCirclePattern extends Pattern { @@ -145,6 +145,35 @@ class RandomCirclePattern extends Pattern {
}
class LinePattern extends Pattern {
constructor({grid=5, angle=Math.random()*2*Math.PI}={})
{
super('line')
this.grid = grid;
this.angle = angle;
this._intersect_trace = false;
}
generate(bounds) {
var ret = [];
var r = Math.random() * 360;
for(var x=0; x<bounds.width * 3; x += this.grid) {
var p = new Path();
p.add(new Point(bounds.x - bounds.width + x,
bounds.y - bounds.height));
p.add(new Point(bounds.x - bounds.width + x,
bounds.y + bounds.height * 2));
p.rotate(this.angle * 360 / (2*Math.PI),
new Point(bounds.x + bounds.width * 0.5,
bounds.y + bounds.height * 0.5));
ret.push(p);
}
return ret;
}
}
class Crown {
constructor(length, width, shape) {
@ -368,7 +397,7 @@ function draw() { @@ -368,7 +397,7 @@ function draw() {
}
var ptrn = null;
var ptrnrand = Math.random() * 5;
var ptrnrand = Math.random() * 6;
if(ptrnrand < 1) {
ptrn = new MiniLinePattern();
} else if(ptrnrand < 2) {
@ -377,6 +406,8 @@ function draw() { @@ -377,6 +406,8 @@ function draw() {
ptrn = new RandomCirclePattern();
} else if(ptrnrand < 4) {
ptrn = new RandomCirclePattern({radius: 1});
} else if(ptrnrand < 5) {
ptrn = new LinePattern({grid: 5 + Math.random() * 3});
}
if(ptrn != null) {
ptrn.apply(t);

Loading…
Cancel
Save