Arduino 如何在处理过程中使用MouseClicked()方法计算特定区域?

Arduino 如何在处理过程中使用MouseClicked()方法计算特定区域?,arduino,mouseevent,processing,Arduino,Mouseevent,Processing,在我的窗口有一个圆圈。我已经实现了void MouseClicked()方法来对鼠标单击事件生效。这意味着只有在圆内单击才能更改圆的颜色并执行相应的操作 但问题是,无论我在何处单击(即使在圆之外),它都会更改圆的颜色。所以我知道mouseClicked()方法不稳定。我该如何解决这个问题 正在处理的我的代码: int colorValue = 0; void setup() { size(450, 255); background(204); } void draw()

在我的窗口有一个圆圈。我已经实现了
void MouseClicked()
方法来对鼠标单击事件生效。这意味着只有在圆内单击才能更改圆的颜色并执行相应的操作

但问题是,无论我在何处单击(即使在圆之外),它都会更改圆的颜色。所以我知道
mouseClicked()
方法不稳定。我该如何解决这个问题

正在处理的我的代码:

int colorValue = 0;
void setup() { 
    size(450, 255); 
    background(204);
} 

void draw() {         
    fill(colorValue);
    ellipse(56, 46, 55, 55);
}
void mouseClicked() {
    if (colorValue == 0) {
        colorValue = 255;
    } else {
        colorValue = 0;
    }
}

您没有检查鼠标是否在圆圈内。您可以使用
dist()
函数来帮助:

int colorValue = 0;
float circleX = 56;
float circleY = 46;
float circleR = 55;

void setup() { 
  size(450, 255); 
  background(204);
  ellipseMode(RADIUS);
 } 

void draw() {         
   fill(colorValue);
   ellipse(circleX, circleY, circleR, circleR);
}
void mouseClicked() {
   if(dist(mouseX, mouseY, circleX, circleY) < circleR){
      if (colorValue == 0) {
         colorValue = 255;
      } else {
         colorValue = 0;
      }
   }
}
int colorValue=0;
浮点数=56;
浮圈=46;
浮点数=55;
无效设置(){
大小(450255);
背景(204);
椭圆模型(半径);
} 
void draw(){
填充(颜色值);
椭圆(圆环、圆环、圆环、圆环);
}
void mouseClicked(){
if(dist(mouseX、mouseY、circleX、circleY)
非常感谢您。它回答了我的问题。是的,万圣节快乐。