# How to introduce gradient into ellipse

**URL:** https://discourse.processing.org/t/how-to-introduce-gradient-into-ellipse/33863
**Category:** Coding Questions
**Created:** [December 1, 2021, 8:49pm UTC](https://discourse.processing.org/t/how-to-introduce-gradient-into-ellipse/33863 "2021-12-01T20:49:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![srb777](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@srb777](https://discourse.processing.org/u/srb777)
#### Post date: [December 1, 2021, 8:49pm UTC](https://discourse.processing.org/t/how-to-introduce-gradient-into-ellipse/33863/1 "2021-12-01T20:49:59Z")

</div>

Hi, I am learning to program with processing and I need help.I need to paint the balls with gradient, It has to look like this:

 ![Captura de pantalla 2021-12-01 a las 21.47.59](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f616ed1f4c67078804160a7c1cd365d70168b211.png)

My code:

```auto
int columns = 20; // Número de columnes
int rows = 10; // Número de files
float diameter; // Diametre dels cercles
float width_columns, height_rows; // Amplada de les columnes i alçada de les files
int r = 255;
int g = 0;
int b = 0;
void setup() {
size(800, 400); // Mida del llenç
background(255); // Fons blanc
textSize(18); // Mida del text
fill(0); // Farcit del text
stroke(0); // Contorn del text
}
void draw() {
width_columns = width/columns; // Calculem l'amplada de les columnes
height_rows = height/rows; // Calculem l'alçada de les files
for(int i=0; i < rows; i++){ // Recorrem les files
for(int j=0; j < columns; j++){ // Recorrem les columnes
noStroke();
fill(r,g,b);
ellipse (j*width_columns + width_columns/4, i*height_rows + height_rows/2,40,40 );
  for (int columns = 0; columns < width; columns++) {
    for(int rows = 0; rows < height; rows++) {
}}
}}
}

```

How can I do it? Thank you so much!

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [December 1, 2021, 9:41pm UTC](https://discourse.processing.org/t/how-to-introduce-gradient-into-ellipse/33863/2 "2021-12-01T21:41:39Z")

</div>

Hello,

Please format your code:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)  
_UPDATE_ Thanks for formatting!

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

There is a Linear Gradient example in there!

Start first with lerping along the columns (or rows) from:

- from _c1_ to _c2_
- _amt_ is from _j_ to _columns_ which is _mapped_ from 0 to 1

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/789cb176995fe8473579e05a951612106afd756a.png)

It looks like you have two nested loops in your code; one is not used.  
I only used one nested loop.

When you are ready think about the next step… this will require some thought!

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e64db6d4364f597b310a0f406c26a35363362f8e.png)

`:)`
