omega
omega

Reputation: 43843

How to interpolate between two colors?

If I have two colors (like in a color object), and then I have a value from 0 to 1 indicating a percent. How can I get the color (in hex or rgb) in between the two given colors with respect to the percent value. For example

If the value was 0, then I would get the color in the far left of the image, if the value was 1, then would get the value in the far right. If it was 0.5, then the color in the center. Etc...

Does anyone know how to do this?

Thanks

enter image description here

Upvotes: 0

Views: 1894

Answers (1)

maraaaaaaaa
maraaaaaaaa

Reputation: 8163

Just cast the colors to Vector4 and do a standard Lerp interpolation

Color color1;
Color color2;

float fraction = 0.5f;
Vector4.Lerp((Vector4)color1, (Vector4)color2, fraction);

Upvotes: 2

Related Questions