我有这个代码来绘制一个数组的圆,并确保他们不会overalapped.我不知道我的问题是什么,因为它没有给出错误,但同时,我也没有看到任何事情发生.
class particle{
constructor(x,y,r){
this.x=x;
this.y=y;
this.r=r;
}
show(){
noFill();
stroke(0);
strokeWeight(1);
ellipse(this.x,this.y,this.r);
}
}
let circles=[];
function setup() {
createCanvas(600, 400);
for (let i=0; i<25; i++){
let x=random(width);
let y=random(height);
let r=50;
circles[i]= new particle(x,y,r);
let overlap=false;
for (let j=0; j<circles.length; j++){
let other=circles[j];
let circle=circles[i];
let d=dist( circle.x,circle.y,other.x,other.y);
if ( d < circle.r/2 + other.r/2){
overlap=true;
}
if (!overlap){
circles.push(circle);
}
}
circles[i].show();
}
}
function draw() {
background(220);
}