首页 热点资讯 义务教育 高等教育 出国留学 考研考公

processing语言编程作业 求解。怎么样黑眼珠跟着鼠标但只在白眼珠里活动?

发布网友 发布时间: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);
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com