xxxxxxxxxx
39
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// Seeking "vehicle" follows the mouse position
// Implements Craig Reynold's autonomous steering behaviors
// One vehicle "seeks"
// See: http://www.red3d.com/cwr/
let vehicles = [];
function setup() {
createCanvas(640, 360);
for (let i = 0; i < 100; i++) {
vehicles[i] = new Vehicle(random(width),random(height));
}
}
function draw() {
background(0);
let target = createVector(mouseX, mouseY);
// Draw an ellipse at the mouse position
fill(127);
stroke(200);
strokeWeight(2);
ellipse(target.x, target.y, 48, 48);
// Call the appropriate steering behaviors for our agents
for (let v of vehicles) {
v.seek(target);
v.update();
v.display();
}
}