xxxxxxxxxx
55
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// Flow Field Following
// Via Reynolds: http://www.red3d.com/cwr/steer/FlowFollow.html
// Using 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(
"Hit space bar to toggle debugging lines.<br>Click the mouse to generate a new flow field."
);
createCanvas(1200, 2000);
// Make a new flow field with "resolution" of 16
flowfield = new FlowField(5);
// 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(255);
// Display the flowfield in "debug" mode
if (debug) flowfield.show();
// // 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;
// }
save('screenshot.png');
}
// Make a new flowfield
function mousePressed() {
flowfield.init();
}