Skip to main content
GameDev.net gamedev.net
🔒 Locked

How do I interpolate colors

Started by jdub Jun 7, 2009 at 12:07 PM 6 replies 19.2k views
Original Post
jdub
jdub
what algorithm can I use interpolate from one RGB color to another?
J.W.
SiCrane
SiCrane
Did you try just interpolating the R, G and B components?
gekko
gekko
Linear interpolation will go the trick.

c = (1 - t) * c0 + t * c1

EDIT: SiCrane beat me to it.
-- gekko
seedy
seedy
Another way of doing the same maths is

Out = C0 + (C1-C0) * t

Where t = 0 to 1

And as SiCrane said , you have to treat the R,G,B parts separately.
swiftcoder
swiftcoder
Linear interpolation of each RGB component is the most straightforward, and the results are often acceptable.

If you need a 'better' interpolation, you can convert the RGB colour to HSV, interpolate the HSV, and convert back to RGB for display.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
jdub
jdub
really? just interpolating the rgb elements separately will do it? I thought there was more to it.
J.W.
ddyer
ddyer
If the colors are similar, then just interpolating the components is
probably acceptable. If the colors are very different, it's a different
story. There is no "right" way to interpolate from red to blue, you have
to decide what sort of intermediate colors you want.
---visit my game site http://www.boardspace.net - free online strategy games
swiftcoder
swiftcoder
Quote:
Original post by ddyer
If the colors are similar, then just interpolating the components is
probably acceptable. If the colors are very different, it's a different
story. There is no "right" way to interpolate from red to blue, you have
to decide what sort of intermediate colors you want.
If you are approaching colour from an artists perspective, HSV interpolation works pretty well.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.