• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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,225
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,337
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,225
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