Counting things in draw()

I have “liquid” (a rectangle) into which I am dropping “objects” (ellipses) of a regular size. When an object passes into the water, I want to add to the height of the water rectangle, and when I take an object out, I want to subtract from it.

How do I count the number of objects in the water without the count value going up whenever void draw() loops?

Thank you!

You have the Position of the rectangle. So its x,y,h and w values. Use them to set bounds in which the ellipses have to be, to add one to the rect. You can just use an if Statement inside draw to check for this, inside a loop if there are multiple objects.