This program demonstrates how to create a smooth color gradient between any two colors.


While gradients are often used for visual effects, perhaps the most useful aspect of this project is the gradient algorithm itself. This code uses linear interpolation, which is a staple of many other algorithms, both graphics and otherwise. Keep a copy in your toolbox!

Download the sample app and source code from GitHub

For a much more advanced demonstration of image gradients, you might investigate the gradient tool source code for my open-source photo editor, PhotoDemon. It supports other gradients shapes (radial, conical, spiral, and more) and is much faster than the simple version linked here.