You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
953 B
43 lines
953 B
const Vector = p5.Vector;
|
|
|
|
function Segment(startx, starty, len, heading){
|
|
this.start = new Vector(startx, starty);
|
|
this.len = len;
|
|
this.reference = 0;
|
|
this.heading = heading;
|
|
this.child = null;
|
|
};
|
|
|
|
Segment.prototype.end = function(){
|
|
angle = this.heading + this.reference;
|
|
let x = this.len * sin(angle) + this.start.x;
|
|
let y = this.len * cos(angle) + this.start.y;
|
|
return new Vector(x,y);
|
|
};
|
|
|
|
|
|
Segment.prototype.update = function(){
|
|
if(this.child){
|
|
this.child.start = this.end();
|
|
this.child.reference = this.heading+this.reference;
|
|
}
|
|
};
|
|
|
|
Segment.prototype.setHeading = function(angle){
|
|
this.heading = angle;
|
|
this.update();
|
|
};
|
|
|
|
Segment.prototype.draw = function(){
|
|
push();
|
|
stroke(255);
|
|
strokeWeight(2);
|
|
line(
|
|
this.start.x,
|
|
this.start.y,
|
|
this.end().x,
|
|
this.end().y);
|
|
pop();
|
|
};
|
|
|
|
|
|
|