# Changing the Color

**URL:** <https://discourse.processing.org/t/changing-the-color/10925>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [May 5, 2019, 3:19am UTC](https://discourse.processing.org/t/changing-the-color/10925 "2019-05-05T03:19:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elangit](https://avatars.discourse-cdn.com/v4/letter/e/ac8455/32.png) [@elangit](https://discourse.processing.org/u/elangit)\
**Post date:** [May 5, 2019, 3:19am UTC](https://discourse.processing.org/t/changing-the-color/10925/1 "2019-05-05T03:19:38Z")

</div>

I’m trying to change the color of each circle depending on the magnitude. However, they all remain blue.

This is the assignment:

- Determine what color the circle for this earthquake should be:
  - If the magnitude is less than 6.3, the color should be (0, 0, 255)
  - If the magnitude is between 6.3 (including 6.3) up to but NOT including 7.0 (i.e. greater than or equal to 6.3 but strictly less than 7.0), the color should be (155, 0, 100)
  - If the magnitude is between 7.0 (including 7.0) up to but NOT including 7.5, the color should be (200, 0, 55)
  - Otherwise, the color should be (255, 0, 0)

And this is the code that I have so far:

```auto
float varM = getMag(datum);
  if (varM < 6.3) {
    color(0,0,255);
  };
  if (6.3 >= varM && varM < 7.0) {
    color(155,0,100);
  };
  if (7.0 <= varM && varM < 7.5) {
    color(255,0,55);
  };

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [May 5, 2019, 3:29am UTC](https://discourse.processing.org/t/changing-the-color/10925/2 "2019-05-05T03:29:51Z")

</div>

To set the color that something is drawn in, you use the `fill()` function, not `color()`.

You can also use if-else statements, and remove some semicolons that you don’t need:

```auto
if (varM < 6.3) {
  fill(0,0,255);
} else if (varM < 7.0) {
  fill(155,0,100);
} else if (varM < 7.5) {
  fill(255,0,55);
}
```

---

<div class="post-metadata">

**Author:** ![elangit](https://avatars.discourse-cdn.com/v4/letter/e/ac8455/32.png) [@elangit](https://discourse.processing.org/u/elangit)\
**Post date:** [May 5, 2019, 3:42am UTC](https://discourse.processing.org/t/changing-the-color/10925/3 "2019-05-05T03:42:49Z")

</div>

Thank you for helping, but it still returns the circle as blue

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [May 5, 2019, 3:43am UTC](https://discourse.processing.org/t/changing-the-color/10925/4 "2019-05-05T03:43:55Z")

</div>

Please post more of your code then. Specifically the bit that draw the circle.

Here’s a small, complete sample:

```auto
float varM;

void setup() {
  size(600, 600);
  varM = 6.5;
}

void draw() {
  background(0);
  if (varM < 6.3) {
    fill(0, 0, 255);
  } else if (varM < 7.0) {
    fill(155, 0, 100);
  } else if (varM < 7.5) {
    fill(255, 0, 55);
  }
  ellipse(300, 300, 100, 100);
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 5, 2019, 4:05am UTC](https://discourse.processing.org/t/changing-the-color/10925/5 "2019-05-05T04:05:23Z")

</div>

please repair your code posting as i indicated in your older question.
