xxxxxxxxxx
55
class Path {
constructor() {
// A path has a radius, i.e how far is it ok for the vehicle to wander off
this.radius = 10;
// A Path is an array of points (p5.Vector objects)
this.points = [];
this.lights = [];
}
// Add a point to the path
addPoint(x, y) {
let point = createVector(x, y);
this.points.push(point);
}
addLight(light){
this.lights.push(light);
}
getStart() {
return this.points[0];
}
getEnd() {
return this.points[this.points.length - 1];
}
// Draw the path
display() {
//Draw light
for(let l of this.lights){
fill(255,0,0);
circle(l.x,l.y-30,10);
}
// Draw thick line for radius
stroke(99);
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(255);
strokeWeight(1);
noFill();
beginShape();
for (let i = 0; i < this.points.length; i++) {
vertex(this.points[i].x, this.points[i].y);
}
endShape();
}
}