I want to implement on my project this sketch about dragging a box.
Instead of one box, I have several circles each drawn with different coordinates in the form
ellipse(lemma23.x, lemma23.y, diameterLemma23, diameterLemma23);
ellipse(law3.x, law3.y, diameterLaw3, diameterLaw3);
ellipse(law2.x, law2.y, diameterLaw2, diameterLaw2);
How do I test if the cursor is on one of the circles?
Here’s a screen shot of my project:

I want to test when cursor is on (or near) a circle so that I can change its position by dragging.
I started with the example in your question. There are a few main differences for drawing multiple shapes:
In the following code, I build upon the example directly although I removed the few lines which change the color of the box when clicked and I reorganized the code into the
MovingEllipseclass so that multiple ellipses can be drawn easily. (This code draws two ellipses.)Note that the code in
draw()checks the position of the mouse for each ellipse, however, I suppose this could be improved upon (i.e. perhaps by creating an array of ellipse positions and looping over the array). Also, for this code to work properly,mousePressedandmouseReleasedmethods need to be copied like themouseDraggedmethod. (I was trying to make my example brief.)Anyway, this is one way to draw multiple ellipses and detect which one should be moved. Hope it helps!