xxxxxxxxxx
63
let vehicle;
function setup() {
createCanvas(800, 800);
vehicle = new Vehicle(100, 100, new Speed(), new Force(), new Slowradius());
}
function draw() {
background(20, 200, 100);
noStroke(0);
text("max speed", +150, 25);
text("max force", +150, 50);
text("slowRadius", +150, 75);
fill(200, 0, 200, 100);
circle(400, 400, 100);
let target = createVector(min(mouseX, this.width), min(mouseY, this.height));
fill(255, 0, 0);
noStroke();
ellipse(target.x, target.y, 32);
noStroke();
fill(50, 0, 50, 20);
ellipse(target.x, target.y,
vehicle.slowRadius.getMaxSlowradius());
let steering = vehicle.arrive(target);
vehicle.applyForce(steering);
vehicle.update();
vehicle.show();
//target.show();
}
class Speed {
constructor() {
this.maxSpeed = createSlider(0, 60, 15);
this.maxSpeed.position(1, 10);
}
getMaxSpeed() {
return this.maxSpeed.value();
}
}
class Force {
constructor() {
this.maxForce = createSlider(1, 20, 5);
this.maxForce.position(1, 35);
}
getMaxForce() {
return this.maxForce.value();
}
}
class Slowradius {
constructor() {
this.slowRadius = createSlider(1, 500, 100);
this.slowRadius.position(1, 60);
}
getMaxSlowradius() {
return this.slowRadius.value();
}
}