xxxxxxxxxx
46
class Path {
constructor() {
//a path has a radius, i.e how far is it ok for the vehicle to wander off
this.radius = 20;
//a Path is an array of points (p5.Vector objects)
this.points = [];
}
//add a point to the path
addPoint(x, y) {
let point = createVector(x, y);
this.points.push(point);
}
getStart() {
return this.points[0];
}
getEnd() {
return this.points[this.points.length - 1];
}
//draw the path
display() {
//draw thick line for radius
stroke(100, 50);
strokeWeight(this.radius * 2);
noFill();
beginShape();
for (let i = 0; i < this.points.length; i++) {
vertex(this.points[i].x, this.points[i].y);
}
endShape();
//draw thin line for center of path
stroke(100);
strokeWeight(1);
noFill();
beginShape();
for (let i = 0; i < this.points.length; i++) {
vertex(this.points[i].x, this.points[i].y);
}
endShape();
}
}