Browse Source

delete old pahts when re-drawing branch

master
Fr3deric 6 years ago
parent
commit
14ca6e1489
  1. 61
      baumgen.js

61
baumgen.js

@ -138,14 +138,23 @@ class Branch { @@ -138,14 +138,23 @@ class Branch {
}
draw(pos) {
var branch = new Path();
if(typeof this._crown !== "undefined") {
this._crown.removeSegments();
delete this._crown;
}
if(typeof this._branch !== "undefined") {
this._branch.removeSegments();
delete this._branch;
}
this._branch = new Path();
var bvec = new Point(Math.cos(this.angle) * this.length,
-1 * Math.sin(this.angle) * this.length);
var end = pos.add(bvec);
branch.strokeColor = 'black';
branch.strokeWidth = 2;
branch.add(pos);
branch.add(end);
this._branch.strokeColor = 'black';
this._branch.strokeWidth = 2;
this._branch.add(pos);
this._branch.add(end);
if(typeof this.crown !== "undefined") {
console.log("CROWN");
@ -155,19 +164,19 @@ class Branch { @@ -155,19 +164,19 @@ class Branch {
var bswidth = this.crown.length * this.crown.width;
var bsvec = new Point(Math.sin(this.angle) * bswidth / 2,
Math.cos(this.angle) * bswidth / 2);
var crown = new Path();
crown.strokeColor = 'black';
crown.fillColor = 'white';
crown.strokeWidth = 2;
crown.closed = true;
//crown.selected = true;
crown.add(end);
crown.add(end.add(cvec.multiply(this.crown.bisect))
this._crown = new Path();
this._crown.strokeColor = 'black';
this._crown.fillColor = 'white';
this._crown.strokeWidth = 2;
this._crown.closed = true;
//this._crown.selected = true;
this._crown.add(end);
this._crown.add(end.add(cvec.multiply(this.crown.bisect))
.add(bsvec));
crown.add(end.add(cvec));
crown.add(end.add(cvec.multiply(this.crown.bisect))
this._crown.add(end.add(cvec));
this._crown.add(end.add(cvec.multiply(this.crown.bisect))
.subtract(bsvec));
console.log(crown);
console.log(this._crown);
} else if(this.crown.shape = "triangle") {
console.log("TRIANGLE");
@ -175,16 +184,16 @@ class Branch { @@ -175,16 +184,16 @@ class Branch {
var bswidth = this.crown.length * this.crown.width;
var bsvec = new Point(Math.sin(this.angle) * bswidth / 2,
Math.cos(this.angle) * bswidth / 2);
var crown = new Path();
crown.strokeColor = 'black';
crown.fillColor = 'white';
crown.strokeWidth = 2;
crown.closed = true;
//crown.selected = true;
crown.add(end.add(bsvec));
crown.add(end.add(cvec));
crown.add(end.subtract(bsvec));
console.log(crown);
this._crown = new Path();
this._crown.strokeColor = 'black';
this._crown.fillColor = 'white';
this._crown.strokeWidth = 2;
this._crown.closed = true;
//this._crown.selected = true;
this._crown.add(end.add(bsvec));
this._crown.add(end.add(cvec));
this._crown.add(end.subtract(bsvec));
console.log(this._crown);
}
}

Loading…
Cancel
Save