Need Help with arrays for background

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

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();
}
}

please format your code with the

</> 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.

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

https://www.processing.org/reference/lerpColor_.html

2 Likes

Also to fix your issue, replace e with 50

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

Don’t try to make his homework…

Or are you him?

1 Like

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

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

1 Like

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

That’s right, but no worries mate

No hard feelings

1 Like