Learn creative coding writing simple programs

82. Program a gradient of colors

With the lerpColor() function we can find a color that is between two other colors. The lerpColor() function takes three parameters. The first two are colors. The third parameters indicates if the new color we get should be closer to the first color or to the second. 0.5 means right in the middle of the two. Numbers below 0.5 mean closer to the first color, and number greater than 0.5 mean closer to the second.
What we do in our program is getting all the possible colors between the first color and the second one by slowly increasing the third parameter from 0 to 1. With each color we get we draw one line. After filling the screen with lines of different colors we get a nice looking vertical gradient.

Tags: gradient, colors, lerpColors

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:
``` void setup() { size(600, 600); } ```