# Change fill of multiple objects at the same time

**URL:** https://discourse.processing.org/t/change-fill-of-multiple-objects-at-the-same-time/9048
**Category:** Coding Questions
**Created:** [March 6, 2019, 11:45pm UTC](https://discourse.processing.org/t/change-fill-of-multiple-objects-at-the-same-time/9048 "2019-03-06T23:45:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![xicolirou](https://avatars.discourse-cdn.com/v4/letter/x/c89c15/32.png) [@xicolirou](https://discourse.processing.org/u/xicolirou)
#### Post date: [March 6, 2019, 11:45pm UTC](https://discourse.processing.org/t/change-fill-of-multiple-objects-at-the-same-time/9048/1 "2019-03-06T23:45:13Z")

</div>

Hi guys, im using a variable to loop a robot and i need a especific robot to change its entire color.  
Do you guys now how to change the fill of multiple objects?

---

<div class="post-metadata">

### Author: ![xicolirou](https://avatars.discourse-cdn.com/v4/letter/x/c89c15/32.png) [@xicolirou](https://discourse.processing.org/u/xicolirou)
#### Post date: [March 6, 2019, 11:47pm UTC](https://discourse.processing.org/t/change-fill-of-multiple-objects-at-the-same-time/9048/2 "2019-03-06T23:47:13Z")

</div>

```auto
  for (int i=0; i < 5; i++) {
    for (int k = 0; k < 2; k++){
      centrox = i*350+200;
      centroy = k*400+300;
      if (i == 3 && k == 1) {
      // every object that has fill(210,175,61); need to change to another color
  
      }

```

---

<div class="post-metadata">

### Author: ![Schred](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/schred/32/13146_2.png) [@Schred](https://discourse.processing.org/u/Schred)
#### Post date: [March 7, 2019, 7:18pm UTC](https://discourse.processing.org/t/change-fill-of-multiple-objects-at-the-same-time/9048/3 "2019-03-07T19:18:42Z")

</div>

You could create a color variable for every object and test if that variable equals a certain value (more on that datatype here: [https://processing.org/reference/color\_datatype.html](https://processing.org/reference/color_datatype.html)).  
You can check if two values are equal by using the “==” operator and the function color() around the value (210, 175, 61). Example:

```auto
color color1 = color(210, 175, 61);

void setup(){
  if(color1 == color(210, 175, 61)){
    //change color
  }else{
    //something
  }
}

```

If you need to know how to test this for every object, I’d need to know how you store the robots. (Are they instances of a class? Do you store them in an Array/ArrayList or separatly?) Also posting more of your code could help. You can mark it as such by putting three ` at the start and the end. 😄

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [March 10, 2019, 6:23pm UTC](https://discourse.processing.org/t/change-fill-of-multiple-objects-at-the-same-time/9048/4 "2019-03-10T18:23:18Z")

</div>

> [@Schred](#):
>
> I’d need to know how you store the robots.

Exactly. If these are objects of a Robot class, then you can assign their color as a class property when you create them, and use that property when you draw them:

```auto
ArrayList<Robot> robots;

void setup() {
  robots = new ArrayList<Robot>();
  color c;
  for (int i=0; i<100; i++) {
    c = color(random(255), random(255), random(255));
    robots.add(new Robot(random(width), random(height), c));
  }
}

void draw(){
  background(128);
  for(Robot r : robots){
    r.display();
  }
}

class Robot {
  PVector loc;
  color c = color(255);
  Robot( float x, float y, color c ) {
    this.c = c;
    this.loc = new PVector(x, y);
  }
  void display() {
    pushStyle();
    fill(c);
    rect(loc.x, loc.y, 10, 10);
    popStyle();
  }
}

```

See for example the objects tutorial:

> **[Objects](https://processing.org/tutorials/objects/)**
>
> The basics of object-oriented programming.
