# Need Help with arrays for background

**URL:** <https://discourse.processing.org/t/need-help-with-arrays-for-background/11577>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [May 25, 2019, 3:32am UTC](https://discourse.processing.org/t/need-help-with-arrays-for-background/11577 "2019-05-25T03:32:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![codingNoob](https://avatars.discourse-cdn.com/v4/letter/c/97f17d/32.png) [@codingNoob](https://discourse.processing.org/u/codingNoob)\
**Post date:** [May 25, 2019, 3:32am UTC](https://discourse.processing.org/t/need-help-with-arrays-for-background/11577/1 "2019-05-25T03:32:41Z")

</div>

So i have an assignment which needs to have a gradient of blue as the background with each shade being 50 pixels and the darkest at the top, but i cant seem to code it so the top 50 pixels is coloured in. please help

```auto
int r = 0;
int g= 0;
int b= 0;
Ball[] balls= new Ball[10];

void setup() {
    size(500,500);
      for (int i=0; i<balls.length; i++) {
    balls[i]= new Ball();
  }
}

void draw() {
  for (int e =0; e<=height; e=e+50)
  {
    fill (r, g, e);
    strokeWeight(0);
    rect(0, e, width, e);
  }
    for (int i=0; i<balls.length; i++) {
    balls[i].display();
}
}

```

---

<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 25, 2019, 4:14am UTC](https://discourse.processing.org/t/need-help-with-arrays-for-background/11577/2 "2019-05-25T04:14:36Z")

</div>

please format your code with the

```auto
</> CODE tag

```

looks like:  
```  
type or paste code here  
```

and clean up all what is not related  
– the whole Ball thing has nothing to do with a background,  
esp as you NOT show the code for that class we could never run your code to help you.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 25, 2019, 11:47am UTC](https://discourse.processing.org/t/need-help-with-arrays-for-background/11577/3 "2019-05-25T11:47:02Z")

</div>

please look at lerpColor() to see how to get all colors between two colors

[https://www.processing.org/reference/lerpColor\_.html](https://www.processing.org/reference/lerpColor_.html)

---

<div class="post-metadata">

**Author:** ![Bobby](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Bobby](https://discourse.processing.org/u/Bobby)\
**Post date:** [May 25, 2019, 3:55pm UTC](https://discourse.processing.org/t/need-help-with-arrays-for-background/11577/5 "2019-05-25T15:55:10Z")

</div>

Also to fix your issue, replace e with 50

```auto
rect(0, e, width, 50);

```

But this is my problem, i cant seem for the top to be DARK blue and the bottom a normal blue. The top is always black for me, then the bottom stops at one shade of blue

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 25, 2019, 4:15pm UTC](https://discourse.processing.org/t/need-help-with-arrays-for-background/11577/6 "2019-05-25T16:15:14Z")

</div>

Don’t try to make his homework…

Or are you him?

---

<div class="post-metadata">

**Author:** ![Bobby](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Bobby](https://discourse.processing.org/u/Bobby)\
**Post date:** [May 25, 2019, 4:20pm UTC](https://discourse.processing.org/t/need-help-with-arrays-for-background/11577/7 "2019-05-25T16:20:21Z")

</div>

What? No lol, i guess we both are trying to do the same thing. And i just noticed his problem so i said how to fix it.  
Was there something i done wrong?  
I can delete the comment if u want

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 25, 2019, 4:21pm UTC](https://discourse.processing.org/t/need-help-with-arrays-for-background/11577/8 "2019-05-25T16:21:42Z")

</div>

If you need help with code you should post it, so others can take a look

---

<div class="post-metadata">

**Author:** ![Bobby](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Bobby](https://discourse.processing.org/u/Bobby)\
**Post date:** [May 25, 2019, 4:23pm UTC](https://discourse.processing.org/t/need-help-with-arrays-for-background/11577/9 "2019-05-25T16:23:52Z")

</div>

Basically, no hijacking posts with other problems correct?  
Sorry, was unintended

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 25, 2019, 4:27pm UTC](https://discourse.processing.org/t/need-help-with-arrays-for-background/11577/10 "2019-05-25T16:27:57Z")

</div>

That’s right, but no worries mate

No hard feelings
