xxxxxxxxxx
100
let WORLD;
let qt
const agents = [];
function setup() {
createCanvas(400, 400);
qt = new Quadtree({
x: 0,
y: 0,
width: width,
height: height
});
WORLD = new World(qt);
agent1 = new Agent(200,200,5);
}
class World {
constructor(qt) {
this.qt = qt;
this.objects = [];
this.createRandomObstructions();
}
createRandomObstructions() {
// Add rectangles
for (let i = 0; i < 10; i++) {
let w = random(20, 50);
let h = random(20, 50);
let x = random(0, width - w);
let y = random(0, height - h);
this.objects.push({
type: rect,
args: [x, y, w, h]
});
}
// Add circles
for (let i = 0; i < 10; i++) {
let r = random(10, 25); // radius
let x = random(r, width - r);
let y = random(r, height - r);
// p5.js circle uses diameter, so multiply radius by 2
this.objects.push({
type: circle,
args: [x, y, r * 2]
});
}
// Add lines
for (let i = 0; i < 10; i++) {
let x1 = random(0, width);
let y1 = random(0, height);
let x2 = random(0, width);
let y2 = random(0, height);
this.objects.push({
type: line,
args: [x1, y1, x2, y2]
});
}
}
render() {
// Render each object using the stored type and arguments
for (const o of this.objects) {
o.type(o.args);
}
}
}
class Agent {
constructor (x,y,spd) {
this.pos = createVector(x,y)
this.max_speed = spd
this.rrt = new Tree(x,y)
}
}
class Tree {
constructor (x,y) {
}
}
class Node {
constructor (x,y,id) {
}
}
function draw() {
background(220);
WORLD.render()
}