xxxxxxxxxx
42
let vehicle;
let target;
let bee;
let flower;
function preload() {
bee = loadImage('bee.png');
flower = loadImage('flower.png');
}
function setup() {
createCanvas(400, 400);
vehicle = new Vehicle(width / 2, height / 2);
}
function draw() {
background('rgb(213,254,213)');
// Offset target to be the center of the flower image
target = createVector(mouseX + 95, mouseY + 90); // Offsetting by half width and height of flower
fill(255, 0, 0);
stroke(0);
strokeWeight(2);
noCursor();
// Draw flower at mouse position
image(flower, mouseX, mouseY, 190, 182);
// Determine behavior based on distance to target
let d = dist(vehicle.pos.x, vehicle.pos.y, target.x, target.y);
let steering;
if (d < 150) {
// If Bee is close to flower, "arrive" behavior with edge avoidance
steering = vehicle.arrive(target);
} else {
// If Bee is far from the flower, "wander" behavior with edge avoidance
steering = vehicle.wander();
}
vehicle.applyForce(steering);
vehicle.update();
vehicle.show();
}