Learn creative coding writing simple programs

95. Is the mouse inside a square?

Calculating if the mouse is inside a circle is very easy. We just need to know the distance from the center of the circle to the mouse pointer, and if this distance is less than the radius of the circle, we are inside. The radius of the circle is the same as half the size of the circle.
Calculating if the mouse is inside a square is a bit more tricky. We need to know four things. Is the mouse below the top border of the square? is the mouse above the bottom of the square? is it on the left side of the right side of the square? is is on the right side of the left border? If those four conditions are all true, then the mouse pointer is inside the square.

Tags: point, rect, square, inside

Code editor

You can make changes to the code below. Then
Below you can ask and answer questions related to this video. If your question is unrelated to the video, please post it at the Processing Forum as I'm unable to help with all of your programs and still have enough free time to eat and sleep :)
comments powered by Disqus