Current File : /home/jeshor13/11bsouth.com/VehiclesNOC/sketch.js |
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// Stay Within Walls
// "Made-up" Steering behavior to stay within walls
var v = [];
var addVehical = true;
var theta = 0
var debug = false;
var d = 100;
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
theta = theta + 0.1
background(51);
if (debug) {
stroke(175);
noFill();
rectMode(CENTER);
rect(width / 2, height / 2, width - d, height - d);
}
if (addVehical) {
if (random(1) < 0.33) {
v.push(new Vehicle(mouseX, mouseY,1, random(3,5)));
} else if (random(1) > 0.66) {
v.push(new ShyVehicle(mouseX, mouseY,2, random(7,9)))
} else {
v.push(new SouldMate(mouseX, mouseY,3, random(5,7)))
}
addVehical = false;
}
if (v.length > 50) {
v.shift()
}
// Call the appropriate steering behaviors for our agents
for (var i = 0; i < v.length; i++) {
v[i].boundaries(i);
v[i].update();
v[i].display();
}
}
function mousePressed() {
//debug = !debug;
addVehical = true;
}