-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit. This is essentially the code Yushuo, expect I moved t…
…he Path and Vehicle classes into their own files.
- Loading branch information
0 parents
commit 4825e7b
Showing
3 changed files
with
476 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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 = 30; | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
boolean debug = true; | ||
|
||
// A path object (series of connected points) | ||
Path path; | ||
|
||
// Two vehicles | ||
Vehicle car1; | ||
Vehicle car2; | ||
|
||
void setup() | ||
{ | ||
size(1000, 1000); | ||
// Call a function to generate new Path object | ||
newPath(); | ||
|
||
// Each vehicle has different maxspeed and maxforce for demo purposes | ||
car1 = new Vehicle(new PVector(0, height/2), 1, 0.04); | ||
car2 = new Vehicle(new PVector(0, height/2), 1, 2); | ||
} | ||
|
||
void draw() | ||
{ | ||
background(255); | ||
// Display the path | ||
path.display(); | ||
// The boids follow the path | ||
car1.follow(path); | ||
car2.follow(path); | ||
// Call the generic run method (update, borders, display, etc.) | ||
car1.run(); | ||
car2.run(); | ||
|
||
//car1.borders(path); | ||
//car2.borders(path); | ||
//car1.borders(); | ||
//car2.borders(); | ||
// Instructions | ||
fill(0); | ||
|
||
} | ||
|
||
// Here define the element of the track | ||
/*void newPath() | ||
{ | ||
// A path is a series of connected points | ||
// A more sophisticated path might be a curve, if you want to have a try. | ||
path = new Path(); | ||
path.addPoint(100, height/2); | ||
path.addPoint(100,height/2+200); | ||
path.addPoint(300,height/2+200); | ||
path.addPoint(300,height/2); | ||
// path.addPoint(200, height/2+5); | ||
}*/ | ||
|
||
|
||
void newPath() { | ||
// A path is a series of connected points | ||
// A more sophisticated path might be a curve | ||
path = new Path(); | ||
float offset = 30; | ||
path.addPoint(offset,offset); | ||
path.addPoint(width-offset,offset); | ||
path.addPoint(width-offset,height-offset); | ||
path.addPoint(width/2,height-offset*3); | ||
path.addPoint(offset,height-offset); | ||
} | ||
|
||
|
||
public void keyPressed() | ||
{ | ||
if (key == ' ') { | ||
debug = !debug; | ||
} | ||
} | ||
|
||
public void mousePressed() | ||
{ | ||
newPath(); | ||
} |
Oops, something went wrong.