Warcraft III resources & community, 2003–2006 · archived

CreateColorString

not rated
Submitted by PepparVariable Change0 downloads
Creates a color string.

ColorStringGet retrieves a color of a color string. If you are to use colors in computation, I recommend you to use color integers as they are *alot* faster.

CreateColorString(255, 127, 0, 63) = "3fff7f00"

Use "|c" in front of a color string when displaying it to a player to color the following text. Use "|r" if you want to revert the color to the default display value.

Source

function CreateColorString takes integer red, integer green, integer blue, integer alpha returns string
    local string charMap = "0123456789abcdef"
    local string cs
    local integer c
    set c = alpha / 0x10
    set cs = SubString(charMap, c, c + 1)
    set c = ModuloInteger(alpha, 0x10)
    set cs = cs + SubString(charMap, c, c + 1)
    set c = red / 0x10
    set cs = cs + SubString(charMap, c, c + 1)
    set c = ModuloInteger(red, 0x10)
    set cs = cs + SubString(charMap, c, c + 1)
    set c = green / 0x10
    set cs = cs + SubString(charMap, c, c + 1)
    set c = ModuloInteger(green, 0x10)
    set cs = cs + SubString(charMap, c, c + 1)
    set c = blue / 0x10
    set cs = cs + SubString(charMap, c, c + 1)
    set c = ModuloInteger(blue, 0x10)
    return cs + SubString(charMap, c, c + 1)
endfunction

function ColorStringGetColor_Child takes string s returns integer
    local string charMapL = "0123456789abcdef"
    local string charMapU = "0123456789ABCDEF"
    local string c1 = SubString(s, 0, 1)
    local string c2 = SubString(s, 1, 2)
    local integer x = 0
    local integer y = 0
    loop
        exitwhen x == 15 or SubString(charMapL, x, x + 1) == c1 or SubString(charMapU, x, x + 1) == c1
        set x = x + 1
    endloop
    loop
        exitwhen y == 15 or SubString(charMapL, y, y + 1) == c2 or SubString(charMapU, y, y + 1) == c2
        set y = y + 1
    endloop
    return x * 16 + y
endfunction
function ColorStringGetRed takes string s returns integer
    return ColorStringGetColor_Child(SubString(s, 2, 4))
endfunction
function ColorStringGetGreen takes string s returns integer
    return ColorStringGetColor_Child(SubString(s, 4, 6))
endfunction
function ColorStringGetBlue takes string s returns integer
    return ColorStringGetColor_Child(SubString(s, 6, 8))
endfunction
function ColorStringGetAlpha takes string s returns integer
    return ColorStringGetColor_Child(SubString(s, 0, 2))
endfunction

Comments

0

No comments.