phpInDev

color_to_hex

string color_to_hex ( int color )

Returns the given color converted into a RRGGBB hex string, which can be used in web pages, for example.

Example 1. using color_to_hex

{ color = color_to_hex(make_color(255, 0, 0)); show_message(color); }

Shows message:

FF0000

Code for color_to_hex.gml

/**
 * Converts color value to RRGGBB hex value.
 *
 * Color : Color to convert into hex
 */
{
    var color, hex, red, green, blue;

    color = argument0;
    hex = "0123456789ABCDEF"
    red = color & 255;
    green = (color >> 8) & 255;
    blue = (color >> 16) & 255;

    return
        string_char_at(hex, (red >> 4) + 1) +
        string_char_at(hex, (red & 15) + 1) +
        string_char_at(hex, (green >> 4) + 1) +
        string_char_at(hex, (green & 15) + 1) +
        string_char_at(hex, (blue >> 4) + 1) +
        string_char_at(hex, (blue & 15) + 1);
}