c# - What's the correct math to fade a color? -
i'm trying fade color, let's yellow white on period of time. i've got timer worked out, , i'm applying new color fine well, fade isn't smooth (e.g. fades weird colors before gets white, of darker predecessor on "fade chain" let's call it). i'm confident that's because math wrong, can't seem find example of math me modify i'm doing.
i pulled basics of colorceiling code question: fade color white (increasing brightness)
right take color, , call extension method increase:
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 can see, each color modified offset ceiling in mind keep exceptions being thrown. extension method, colorceiling looks this:
public static int colorceiling(this byte val, byte modifier, byte ceiling = 255) { return (val + modifier > ceiling) ? ceiling : val + modifier; } now, i'm confident colorceiling problem, can't find math. feel incrementing argb wrong approach, seems you'd want 50% lighter, don't know means far code.
here's idea might work.
don't math in red-green-blue space. instead treat colour having 3 components:
- hue (is red, orange, yellow, green, blue, violet, etc),
- saturation (how intense color?)
- value (how blackness in color?)
there algorithms converting rgb hsv; them up. place start:
http://en.wikipedia.org/wiki/hsl_and_hsv
now when fading 1 color other, take steps along hsv axes, not along rgb axes.
Comments
Post a Comment