mirror of
https://github.com/processing/processing4.git
synced 2026-02-07 23:59:21 +01:00
51 lines
969 B
Plaintext
51 lines
969 B
Plaintext
// Path Following
|
|
// Daniel Shiffman <http://www.shiffman.net>
|
|
// The Nature of Code
|
|
|
|
class Path {
|
|
|
|
// A Path is an arraylist of points (PVector objects)
|
|
ArrayList<PVector> points;
|
|
// A path has a radius, i.e how far is it ok for the boid to wander off
|
|
float radius;
|
|
|
|
Path() {
|
|
// Arbitrary radius of 20
|
|
radius = 20;
|
|
points = new ArrayList<PVector>();
|
|
}
|
|
|
|
// Add a point to the path
|
|
void addPoint(float x, float y) {
|
|
PVector point = new PVector(x, y);
|
|
points.add(point);
|
|
}
|
|
|
|
// Draw the path
|
|
void display() {
|
|
strokeJoin(ROUND);
|
|
|
|
// Draw thick line for radius
|
|
stroke(175);
|
|
strokeWeight(radius*2);
|
|
noFill();
|
|
beginShape();
|
|
for (PVector v : points) {
|
|
vertex(v.x, v.y);
|
|
}
|
|
endShape(CLOSE);
|
|
// Draw thin line for center of path
|
|
stroke(0);
|
|
strokeWeight(1);
|
|
noFill();
|
|
beginShape();
|
|
for (PVector v : points) {
|
|
vertex(v.x, v.y);
|
|
}
|
|
endShape(CLOSE);
|
|
}
|
|
}
|
|
|
|
|
|
|