I am trying to fade out a color, say Yellow to White for a certain period of time. I have a timer, and I also apply a new color, but the fading is not smooth (for example, it disappears in some strange colors before it falls into White , some of which are darker than their predecessor on the βfade chainβ, let him be called) . I am sure that since the math is wrong, but I just can't find a good math example for me to change what I am doing.
I even pulled the basics of the ColorCeiling code from this question: Wither color to white (increase brightness)
Now I take the color and call the Increase extension method:
dataGridViewResults.Rows[0].DefaultCellStyle.BackColor.Increase(50); public static Color Increase(this Color color, byte offset) { return Color.FromArgb( color.A.ColorCeiling(offset), color.R.ColorCeiling(offset), color.G.ColorCeiling(offset), color.B.ColorCeiling(offset)); }
and, as you can see, each color is then changed by offset with the ceiling to eliminate exceptions. This ColorCeiling extension method is as follows:
public static int ColorCeiling(this byte val, byte modifier, byte ceiling = 255) { return (val + modifier > ceiling) ? ceiling : val + modifier; }
Now I am sure that the problem is ColorCeiling , but I honestly just can not find the math. I honestly feel that just building ARGB is almost certainly the wrong approach, it looks like you would say that I want you to be 50% lighter, but I just don't know what that means for code.
source share