• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Color Gradient func

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
Could someone make a function for color grading a text? I want it to color from red-orange-yellow-green starting at 0 (red) and ending at 1 (green) Probably 0.2 should be red and 0.8 should be green though. Should I just make a bunch if if statements or can I do it some other way?

JASS:
private function GetString takes real r returns string
    local integer i = R2I(r*100)
    local string s
    if (r < 0.2) then
        set s = "|c00ff0000"
    elseif (r >= 0.2 and r < 0.4) then
        set s = "|c00bf3f00"
    elseif (r >= 0.4 and r < 0.6) then
        set s =  "|c007f7f00"
    elseif (r >= 0.6 and r < 0.8) then
        set s = "|c003fbf00"
    elseif (r >= 0.8) then 
        set s = "|c0000ff00"
    endif
    return s + I2S(i) + "%|r"
endfunction

Made it like this, how would you do it?
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
I would avoid such functions because they are bound to generate a ton of moderate length string leaks.
The tag string corresponds to a 32 bit colour code stored in hex. As such you can generate any colour smoothly simply by performing a base conversion from a native integer to hex. This is best done in 8 bit segments representing a single colour channel.
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
I would avoid such functions because they are bound to generate a ton of moderate length string leaks.
The tag string corresponds to a 32 bit colour code stored in hex. As such you can generate any colour smoothly simply by performing a base conversion from a native integer to hex. This is best done in 8 bit segments representing a single colour channel.

Im sorry but I have no idea what you mean tbh. Changed the function in the OP.

How would the string leak? if I move this to the main block is it okey then?
 
Last edited:
Level 15
Joined
Aug 7, 2013
Messages
1,338
I believe DSG is suggesting you representing your color codes in hexadecimal / as an integer and not as a string,in order to save string leaks.

Waiting for his clarification, however.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
How would the string leak?
By only being used once and being unique. WC3 uses a string table and every unique string generated by triggers remains in this table until the end of the session. The more strings in the table, the slower making new strings becomes until you get to the point where every time a trigger makes a new string several game frames are dropped.

if I move this to the main block is it okey then?
No as there is no solution to string leaks next to make fewer unique strings.

I believe DSG is suggesting you representing your color codes in hexadecimal / as an integer and not as a string, in order to save string leaks.
The integer to hex is how to generate the tags from mathematical colours (for a smooth gradient). Nothing about stopping leaks.

Most of the leaks will occur in the final step where you concatenate a rainbow coloured text element since it will make a massive string 1 character at a time (if each character is uniquely coloured).

Do remember that WC3 strings are limited in length. Using too many colour codes generated automatically could easily cause a string to exceed this limit.
 
Status
Not open for further replies.
Top