**This is part of programming course, and the modules we are asked to use are not generally used otherwise. I will do my best to explain my code (though it is pretty self-explanatory)
EDIT: If you're curious, I must use Myro, and the code I use to get mouse click coordinates is: mouseX, mouseY = win.getMouse() # "win" refers to a Window object
I am creating "buttons" that when clicked with perform some form of action. I have three different shapes I use: rectangles, circles, and triangles.
For the rectangle:
# The numbers used in this example are the coordinates on an XY plane
# mouseX refers to the X coord of a recent mouse click; mouseY on the Y axis
if mouseX >= 70 and mouseX <= 120:
if mouseY >= 10 and mouseY <= 35:
print("rectangle button clicked")
For the circle, I got help from this question, and ended up with this code:
# mouseX and mouseY, same as rectangle example
if sqrt((mouseX-660)**2 + (mouseY-270)**2) <= 30:
print("circle button clicked")
The last shape I am attempting to work with is a triangle. I'm not sure how I would go about ensuring mouseX
and mouseY
are within the coords for the shape. I'm rather terrible at math, but I'm assuming there is some formula that can be used (e.g. the circle example). Thanks much.
I found the answer as part of this question, written in C (I believe). I've rewritten the code into Python and will leave it here for others.
The code:
Testing: