Warcraft III resources & community, 2003–2006 · archived

StringColorCrossFade

not rated
Submitted by PepparText Parsing0 downloads
Inserts color strings to the string to create a "fade"-effect from color c1 to color c2. Steps control how many "chunks" of text are colored. Change this to an appropriate and balanced value.

Steps must be: 256 >= steps >= 1. Recommended values are 25, 50 or 100.

The function doesn't allow the resulting string to be greater than 1023 characters long (Exception: the string is originally longer than 1023 characters). It auto-adjusts the quality of the fade to meet this limit, and if it cannot insert *any* coloring without exceeding this limit the string remains uncolored.

Requires: ColorIntegerGet (CreateColorInteger), CreateColorString

Source

function StringColorCrossFade takes string s, integer c1, integer c2, integer steps returns string
    local integer length = StringLength(s)
    local integer length_lim = 1023
    local string out = ""
    local real lim = I2R(IMinBJ((length_lim - 2 - length) / 10, IMinBJ(256, IMinBJ(length, steps))))
    local real i = 0
    local real r = I2R(ColorIntegerGetRed(c1))
    local real g = I2R(ColorIntegerGetGreen(c1))
    local real b = I2R(ColorIntegerGetBlue(c1))
    local real a = I2R(ColorIntegerGetAlpha(c1))
    local real delta_i
    local real delta_r
    local real delta_g
    local real delta_b
    local real delta_a
    if lim < 1 then
        return s
    endif
    set delta_i = I2R(length) / lim
    set delta_r = (I2R(ColorIntegerGetRed(c2)) - r) / lim
    set delta_g = (I2R(ColorIntegerGetGreen(c2)) - g) / lim
    set delta_b = (I2R(ColorIntegerGetBlue(c2)) - b) / lim
    set delta_a = (I2R(ColorIntegerGetAlpha(c2)) - a) / lim
    loop
        exitwhen lim <= 0
        set out = out + "|c" + CreateColorString(R2I(r), R2I(g), R2I(b), R2I(a)) + SubString(s, R2I(i + 0.5), R2I(i + delta_i + 0.5))
        set i = i + delta_i
        set r = r + delta_r
        set g = g + delta_g
        set b = b + delta_b
        set a = a + delta_a
        set lim = lim - 1
    endloop
    return out + "|r"
endfunction

Comments

0

No comments.