I’m creating some custom Swing components that I’d like to have fade from one color to another. At the moment I’m converting from RGB to HSB then incrementing through the Hue value and converting back to RGB before painting, work’s fine.
However, this cycles through all the colors (i.e. attempting to fade from blue to green cycles through yellow, orange, red etc). Is there a decent algorithm/method to fade directly from one color into another?
Edit: I already had it updating via a Swing Timer (I try to steer clear of touching components with Threads like the plague). I’ll have a go this evening with your suggestions, THANKS GUYS!
Based on this example, the
Queue<Color>below cycles fromColor.greentoColor.blueand back toColor.greenagain inN = 32steps. Note thatColor.greenis numerically less thanColor.bluein the HSB model. See also this related example using HSB.