# Counting things in draw()

**URL:** <https://discourse.processing.org/t/counting-things-in-draw/5396>\
**Category:** Coding Questions\
**Created:** [November 10, 2018, 4:12am UTC](https://discourse.processing.org/t/counting-things-in-draw/5396 "2018-11-10T04:12:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![germaine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/germaine/32/2103_2.png) [@germaine](https://discourse.processing.org/u/germaine)\
**Post date:** [November 10, 2018, 4:12am UTC](https://discourse.processing.org/t/counting-things-in-draw/5396/1 "2018-11-10T04:12:41Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 10, 2018, 8:45am UTC](https://discourse.processing.org/t/counting-things-in-draw/5396/2 "2018-11-10T08:45:57Z")

</div>

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.
