SA-MP Forums Archive
Fade any colour to white - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Fade any colour to white (/showthread.php?tid=642310)



Fade any colour to white - Misiur - 28.09.2017

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?


Re: Fade any colour to white - Misiur - 28.09.2017

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


Re: Fade any colour to white - Sew_Sumi - 28.09.2017

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

He had color to color, and fades, and all things madness.


Re: Fade any colour to white - Misiur - 28.09.2017

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