Hello, I’m new to programming and I was just playing around with processing.
I created a program where a circle follows your mouse and grows if it touches the edges of the screen. For some reason it works only when the circle is on the left side of the screen, but not the right.
Have you tried debugging your code? Here’s a guide that might help you:
For example, if I were you I would print out the value of the mouseX variable. I think you’ll find that it doesn’t quite get to the exact value of the width variable.
This is because if you have a window that’s 800 pixels wide, then the rightmost pixel is 799. This is because the leftmost pixel is 0 instead of 1.
Also, I think you’ll find that if you move the mouse very fast, the value of mouseX can move by several pixels each frame and the value will not be exactly 0 or width - 1 anyway. You might want to check for a distance instead of an exact value.
Screen width is 800. Coordinates starts from 0 on the left side, so coordinate of the right side is 799. This applies to arrays or any other indexing starting from zero. You need to decrease one from the end to get the last index or a coordinate in this case.