0

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

omega
  • 40,311
  • 81
  • 251
  • 474

1 Answers1

2

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);
maraaaaaaaa
  • 7,749
  • 2
  • 22
  • 37