How to use this code with mousePressed?

Yes.

Also look at mouseX and mouseY in the reference

https://www.processing.org/reference/

1 Like