top quadrant of a point in correlation to mouse

Hey all, I am having a bit of a difficult time trying to measure the top/bottom quadrants of an ellipse in correlation to the mouse. So, if mouse positions are on top quadrant, do this, else, do that.

float fishX;
float fishY;
float theta; 
float x;
float y;
float radius;


void setup() {
  size(640, 360); 
  noStroke();  
  x = mouseX;
  y = mouseY;
  fishX =width/2;
  fishY = height/2;
  radius = dist(fishX, fishY, x,y);

}

void draw() { 
  background(255);


x= radius*cos(theta);
y = radius * sin(theta);









if(radius <= 100 && theta > 0 && theta < PI){

println("INSIDE");
  background(0,0, 255);


}

else if ( radius > 100 || theta > PI && theta < TWO_PI){

 println ("OUTSIDE");
 background(0,255,0);

}
  fill(255,0,0);
  ellipse(fishX, fishY, 30,30);


}

Answers

  • edited January 2014 Answer ✓

    I think this is what you want ...

    float x;
    float y;
    float radius=30;
    
    void setup() {
      size(640, 360); 
      noStroke();  
      x = width/2;
      y = height/2;
    }
    
    void draw() { 
    
      if ( dist(mouseX, mouseY, x, y)<radius &&  mouseY < y) {
        println("TOP");
        background(0, 0, 255);
      }
      else if ( dist(mouseX, mouseY, x, y)<radius &&  mouseY > y) {
        println("BOTTOM");
        background(255, 0, 255);
      }
      else {
        background(-1);
      }
    
      fill(255, 0, 0);
      ellipse(x, y, radius*2, radius*2);
    }
    
  • Great! This is exactly what I am looking for. thanks!

Sign In or Register to comment.