发布网友 发布时间:2022-04-24 13:34
共1个回答
热心网友 时间:2023-10-14 15:39
float ox1 = 110;
float oy1 = height/2;
float ox2 = 190;
float oy2 = height/2;
void setup(){
size(300,300);
smooth();
noStroke();
}
void draw(){
background(120);
float r1 = dist(mouseX,mouseY,width/2-40,height/2);
float si1 = (mouseX-(width/2-40))/r1;
float co1 = (mouseY-height/2)/r1;
float r2 = dist(mouseX,mouseY,width/2+40,height/2);
float si2 = (mouseX-(width/2+40))/r2;
float co2 = (mouseY-height/2)/r2;
if(abs(r1)<20){
ox1 = mouseX;
oy1 = mouseY;
}else{
ox1 = width/2+20*si1-40;
oy1 = height/2+20*co1;
}
if(abs(r2)<20){
ox2 = mouseX;
oy2 = mouseY;
}else{
ox2 = width/2+20*si2+40;
oy2 = height/2+20*co2;
}
fill(255);
ellipse(width/2-40,height/2,60,60);
ellipse(width/2+40,height/2,60,60);
fill(0);
ellipse(ox1,oy1,20,20);
ellipse(ox2,oy2,20,20);
}