# Image keeps being redrawn after 'deleted'

**URL:** <https://discourse.processing.org/t/image-keeps-being-redrawn-after-deleted/39542>\
**Category:** Electronics (Arduino, etc.)\
**Tags:** homework\
**Created:** [November 1, 2022, 10:13am UTC](https://discourse.processing.org/t/image-keeps-being-redrawn-after-deleted/39542 "2022-11-01T10:13:30Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [November 3, 2022, 1:32pm UTC](https://discourse.processing.org/t/image-keeps-being-redrawn-after-deleted/39542/5 "2022-11-03T13:32:56Z")

</div>

Hi @Ties2901,

you can try s.th like this… (not tested but should work. maybe typos but you should get the idea)  
And please rename class Object to better naming ie. class Food…  
Why renaming?  
[Java Object Class - Javatpoint](https://www.javatpoint.com/object-class#:~:text=The%20Object%20class%20is%20the,class%20object%2C%20know%20as%20upcasting).

Cheers  
— mnse

> [@Ties2901](#):
>
> ```auto
> //initializing an array of objects of the class Object.
> ArrayList<Object> objects;
> int gotFood = 0;
> 
> ```

> [@Ties2901](#):
>
> ```auto
> objects = new ArrayList<Object>() ;
> for (int i=0; i<20; i++) {
> // giving a random value between 0 and the length of the array, which will be
> // converted into an integer, which will give a random object out of the array
> int index = int(random(0, food.length));
> // the object stores a variable that indicates which image it will display
> objects.add(new Object(food[index]);
> }
> 
> ```

> [@Ties2901](#):
>
> ```auto
> for (int i=objects.size()-1; i >= 0; i--) {
> Object obj = objects.get(i);
> if (obj.dissappear()) {
> SizeW += 10;
> SizeH += 10;
> gotFood++;
> objects.remove(i);
> }
> else {
> obj.display();
> }
> }
> 
> ```

> [@Ties2901](#):
>
> ```auto
> boolean dissappear() {
> if (dist(objectlocationX, objectlocationY, EgbertX, EgbertY) < 30) {
> return true;
> }
> return false;
> // or simply as a consequence
> // return dist(objectlocationX, objectlocationY, EgbertX, EgbertY) < 30;
> }
> 
> ```

---

_[View the full topic](https://discourse.processing.org/t/image-keeps-being-redrawn-after-deleted/39542)._
