xxxxxxxxxx
44
function setup() {
createCanvas(400, 400);
center = createVector(width / 2, height / 2);
boxes = [];
rectMode(CENTER);
for(i = 0; i < height / 20 - 1; i++){
boxes[boxes.length] = new Box(width / 2, i * 35);
}
}
function draw() {
background(220);
for(i = 0; i < boxes.length; i++){
boxes[i].update();
}
}
class Box{
constructor(x, y, index){
this.pos = createVector(x, y);
this.vel = createVector(1, 0);
this.dist = p5.Vector.sub(center, this.pos);
this.dist2 = createVector(0, 0);
this.td = this.dist.mag();
this.reaim = createVector(0, 0);
// this.vel.setMag(this.dist.mag() / 100 + sqrt(this.dist.mag()) * 0.1);
this.index = index;
}
update(){
this.dist = p5.Vector.sub(this.pos, center);
// this.dist2 = this.dist;
// this.dist.setMag(this.td);
// this.reaim = p5.Vector.sub(this.dist2, this.dist);
this.vel.setHeading(this.dist.heading() + HALF_PI + 0.024);
// this.pos.add(this.reaim);
this.pos.add(this.vel);
noFill();
circle(width / 2, height / 2, this.dist.mag() * 2);
fill(255);
square(this.pos.x, this.pos.y, 10);
}
}