We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, first post and I have a relatively quick question. I'm writing a program in which the user has to press a button and the button is an ellipse. How do I limit the range of available pressing area into an ellipse. Right now I have it as -
if (mouseX > width/2-55 && mouseX < width/2-5 && mouseY > 335 && mouseY < 385 && mousePressed) {
}
This is simply limiting the pressing area to the rectangle that the ellipse fits into. How do I make the click box an ellipse the same size as the object? This is the ellipse btw.
ellipse(width/2-30, 360, 50, 50);
Thanks. Sorry if this violates any rules. I will flag it completed or delete the post once I have some help.
Answers
In this online game example, which uses ellipse() balloons:
http://studio.processingtogether.com/sp/pad/export/ro.9V7R1wu55fOiN/latest
It uses this method for mouse-within-ellipse-area detection:
Where x & y are Balloon's coordinates and rw & rh are its radius. :-B
You don't "limit mousePressed range", you just check that the mousePressed event happened within your ellipse.
Since your ellipse is just a circle, you can use the dist() function to check if the click coordinates falls within a given distance of the center of the circle.
Dunno how I've missed that was a mere circle, and not an ellipsoid shape! 8-}
A much simplified formula for circles: :bz
return sq(mouseX - x) + sq(mouseY - y) < rad*rad;