xxxxxxxxxx
26
let agent;
let velocity;
let acceleration;
let topspeed = 5;
function setup() {
createCanvas(800, 200);
agent = createVector(0, 0);
velocity = createVector(0, 10);
acceleration = createVector();
}
function draw() {
background(2, 6, 23);
let centerPos = createVector(width / 2, height / 2);
let direction = p5.Vector.sub(centerPos, agent);
acceleration = direction.setMag(0.2);
velocity.add(acceleration);
velocity.limit(topspeed);
agent.add(velocity);
fill(255, 100, 100);
ellipse(agent.x, agent.y, 20, 20);
}