xxxxxxxxxx
42
//use this variable to decide whether to draw all the stuff
let debug = true;
//Flowfield object
let flowfield;
//an ArrayList of vehicles
let vehicles = [];
function setup() {
let text = createP("Click to generate a new flow field");
text.position(15, 5);
createCanvas(560,390);
//make a new flow field with "resolution" of 16
flowfield = new FlowField(20);
//make a whole bunch of vehicles with random maxspeed and maxforce values
for (let i = 0; i < 120; i++) {
vehicles.push(new Vehicle(random(width), random(height), random(2, 5), random(0.1, 0.5)));
}
}
function draw() {
background(220);
//display the flowfield in "debug" mode
if (debug) flowfield.display();
//tell all the vehicles to follow the flow field
for (let i = 0; i < vehicles.length; i++) {
vehicles[i].follow(flowfield);
vehicles[i].run();
}
}
// function keyPressed() {
// if (key == ' ') {
// debug = !debug;
// }
// }
//make a new flowfield
function mousePressed() {
flowfield.init();
}