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.
Code editor
You can make changes to the code below. Then
Reference
color
colorMode
draw
float
for
height
int
lerpColor
line
map
random
setup
size
stroke
void
width
color
colorMode
draw
float
for
height
int
lerpColor
line
map
random
setup
size
stroke
void
width
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); } ```