Fade any colour to white
#1

Hello. Given starting colour, say 0xBADA55 I need a function which fades it to white by given percentage. So:

pawn Код:
new start = 0xBADA55;
FadeToWhite(start, 1.0); // 100% fade, white 0xFFFFFF
FadeToWhite(start, 0.5); // 50% fade, less green, more white, somewhere around 0xC4D392
Did someone already written such function in PAWN?
Reply
#2

pawn Код:
FadeToWhite(colour, Float:percent)
{
    if (percent <= 0.0) {
        return colour;
    }

    if (percent >= 1.0) {
        return 0xFFFFFF;
    }

    new
        r = (colour >> 16) & 0xFF,
        g = (colour >> 8) & 0xFF,
        b = colour & 0xFF,
        dr = floatround((0xFF - r) * percent),
        dg = floatround((0xFF - g) * percent),
        db = floatround((0xFF - b) * percent)
    ;

    return ((r + dr) << 16) + ((g + dg) << 8) + (b + db);
}
Good enough
Reply
#3

YSI had something along these lines, or something ****** did had it...

He had color to color, and fades, and all things madness.
Reply
#4

I know, it's still there in y_text https://github.com/Misiur/YSI-Includ....inc#L442-L455 just not as a self-contained function
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)