Sign in to follow this  
Followers 0
potato

Dynamic Color

1 post in this topic

Here's example of dynamic color code (Im new to LUA maybe this can emplement easier) :

local function dynColor(min, max, value)
    local MaxC = 255
    local MinC = 0
    local DtC = 255

    if (value>=max) then
        red=MaxC;
        green=MinC;
        blue=MinC;
        return;    
    elseif (value<=min)    then
        red=MinC;
        green=MinC;
        blue=MaxC;
        return;
    end

    local step = (max-min)/4.0;
    local dt = value-min;

    if (dt <= step) then    
        red   = MinC;
        green = math.floor(dt*(DtC/step));
        blue  = MaxC;
    else
        dt = dt-step;
        if (dt <= step) then    
            red   = MinC;
            green = MaxC;
            blue  = math.floor((step-dt)*(DtC/step));    
        else
            dt = dt-step;
            if(dt <= step) then
                red   = math.floor(dt*(DtC/step));
                green = MaxC;
                blue  = MinC;    
                else    
                    dt = dt-step;
                    red   = MaxC;
                    green = math.floor((step-dt)*(DtC/step));
                    blue  = MinC;
                end    
        end        
    end    
    return;
end

 


Also there video demonstartion (Look at the arc health bar) :

 

Sharqosity likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0