Files
sunny9898/task8/_ref/noc-examples-processing-master/chp06_agents/Alignment/Alignment.pde
louiscklaw 5637fbf94f update,
2025-02-01 02:07:58 +08:00

45 lines
879 B
Plaintext

// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// Separation
// Via Reynolds: http://www.red3d.com/cwr/steer/
// A list of vehicles
ArrayList<Vehicle> vehicles;
void setup() {
size(640,360);
// We are now making random vehicles and storing them in an ArrayList
vehicles = new ArrayList<Vehicle>();
for (int i = 0; i < 100; i++) {
vehicles.add(new Vehicle(random(width),random(height)));
}
}
void draw() {
background(255);
for (Vehicle v : vehicles) {
// Path following and separation are worked on in this function
v.align(vehicles);
// Call the generic run method (update, borders, display, etc.)
v.update();
v.borders();
v.display();
}
// Instructions
fill(0);
text("Drag the mouse to generate new vehicles.",10,height-16);
}
void mouseDragged() {
vehicles.add(new Vehicle(mouseX,mouseY));
}