Generate gradient using only one color
android, colors, java, rgb
Solution
I think the best is converting from the RGB to the HSV space:
public int enlight(int color, float amount) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] = Math.min(1.0f, amount * hsv[2]);
return Color.HSVToColor(hsv);
}
then you can enlight a color simply by incrementing the `v` (value) component, and then converting back to RGB if needed with the very same Android API `Color`
Problem
I have one color, for example `0xFF0000`. I want to create simple gradient using only this color as start-point information. The second point will be lighter color the first color. For example if I have value - `0xFF0000` and I want to get `0xCC0000` from it. Then I can draw simple gradient. so second color should be, for example 10 or 20% lighter then first Hard code values are not acceptable. User will select the color from the color wheel and application should automatically generate the second color to draw simple gradient. Is there any algorithm or way to to implement this? Probably algorithm will count what higher: R or G or B and then parallel decrease other components, or something... I'm not sure how this works. P.S.: I'm using android SDK