System Unit Colour Transition System

uberfoop

~=Admiral Stukov=~
Reaction score
177
Requires vJass

Unit Colour Transition System

ucts.jpg

Basic function list:
JASS:

//Main methods:
static method create takes unit u, real CurrentR, real CurrentG, real CurrentB, real CurrentA returns UCT
method SetInstantRGBA takes real r, real g, real b, real a, boolean targettoo returns nothing
method TargetRGBA takes real r, real g, real b, real a returns nothing
method SetRate takes real r returns nothing
//================================
//Directly use only if color-related members are changed without using the above methods:
method UCTAdd takes nothing returns nothing


JASS:

//==============================================================================
//                   Uberfoop - Unit Colour Transition System 
//======================================1.0=====================================
//
//   *Requires:
//   vJass
//
//   *UCTS is a system allowing a simple means of smoothly transitioning a
//   unit's RGB and Alpha values to another set of values linearily. It works by
//   storing a unit in a struct along with target RGB and Alpha values to
//   approach.
//
//   *Implimentation:
//   Create a trigger call UCTS, go to Edit -> 'Convert to custom text', and
//   replace everything in it with this script.
//   The first global block in the library contains two items along with
//   descriptions of how to use them.
//
//   *Use:
//        *A UCT struct is an object with a unit and data for current RGBA and target
//         RGBA data within in. When methods that change color values are called, 
//         and target values don't match up with current values, the struct is made
//         active and the member unit's vertex coloring will change until the RGBA
//         reaches target RGBA.
//        *UCTS uses 0 through 255 for RGBA values.
//        *The system itself only stores the unit to the UCT struct. An attachment
//         system must be used to reference a UCT struct from a unit.
//        *Useful UCT struct methods:
//             *create takes unit u, real CurrentR, real CurrentG, real CurrentB, real CurrentA
//              Sets up the current values and changes the vertex coloring of the unit instantly
//              to the specified values.
//             *SetRate takes real r
//              Takes r values in change/second, scales them, and inputs the data to
//              the struct.
//             *SetInstantRGBA takes real r, real g, real b, real a, boolean targettoo
//              Replaces SetUnitVertexColor if this system is in use, so that the system
//              knows the changes have taken place. If boolean targettoo is true, the new
//              values will be applied to the target values as well, ceasing any current unit
//              color transitioning.
//             *TargetRGBA takes real r, real g, real b, real a
//              Sets only the target RGBA values.
//             ***SetInstantRGBA and TargetRGBA both activate the struct if current values
//                and target values don't match. If color value members of the struct
//                are changed directly without using these methods, method UCTAdd,
//                which takes nothing, must be called, to ensure that color transition takes
//                place.
//
//==============================================================================

library UCTS initializer Init

//Configurable globals
globals
    private constant real UCTS_TIMEOUT = .03125 //Interval between calls of callback function
                                        //Increasing this will slow transitions for a given 'rate',
                                        //and be choppier, but improve performance
                                        //.03125 is 32 callbacks per second

    private constant real UCTS_RATE = 1 //Default maximum quantity of change per call of callback
endglobals                              //Increasing this will increase the default rate of transition
                                        //'rate' member of UCT structs default to this value
                                        //True rate of RGBA change will equal rate/UCTS_TIMEOUT


//stuff
globals
    private timer UCTS_TIMER
    private UCT array UCTS_ACTIVE
    private integer UCTS_QUANTITY = -1
endglobals


//Applies the color transitions themselves
private function UCTSCallback takes nothing returns nothing
    local integer i = 0
    local real m
    local UCT s
    loop
        exitwhen i > UCTS_QUANTITY
        set s = UCTS_ACTIVE<i>
        set m = s.tr - s.r
        if m*m &lt;= s.rate*s.rate then
            set s.r = s.tr
        elseif m &lt; 1 then
            set s.r = s.r - s.rate
        else
            set s.r = s.r + s.rate
        endif
        set m = s.tg - s.g
        if m*m &lt;= s.rate*s.rate then
            set s.g = s.tg
        elseif m &lt; 1 then
            set s.g = s.g - s.rate
        else
            set s.g = s.g + s.rate
        endif
        set m = s.tb - s.b
        if m*m &lt;= s.rate*s.rate then
            set s.b = s.tb
        elseif m &lt; 1 then
            set s.b = s.b - s.rate
        else
            set s.b = s.b + s.rate
        endif
        set m = s.ta - s.a
        if m*m &lt;= s.rate*s.rate then
            set s.a = s.ta
        elseif m &lt; 1 then
            set s.a = s.a - s.rate
        else
            set s.a = s.a + s.rate
        endif
        if s.r == s.tr and s.g == s.tg and s.b == s.tb and s.a == s.ta then
            set UCTS_ACTIVE<i> = UCTS_ACTIVE[UCTS_QUANTITY]
            set UCTS_QUANTITY = UCTS_QUANTITY - 1
            set s.SAFETY = -1
        endif
        call SetUnitVertexColor(s.u,R2I(s.r),R2I(s.g),R2I(s.b),R2I(s.a))
        set i = i + 1
    endloop
    if UCTS_QUANTITY == -1 then
        call PauseTimer(UCTS_TIMER)
    endif
endfunction

//===============//
//Start of struct//
//===============//
struct UCT

    unit u

    //Current RGBA values for a unit
    real r
    real g
    real b
    real a

    //RGBA values to approach
    real tr
    real tg
    real tb
    real ta

    //Safety
    integer SAFETY

    //Rate, change per callback
    real rate

    //Unit u will apply the stated basic RGBA values immediately
    static method create takes unit u, real CurrentR, real CurrentG, real CurrentB, real CurrentA returns UCT
        local UCT s = UCT.allocate()
        set s.u = u
        set s.r = CurrentR
        set s.g = CurrentG
        set s.b = CurrentB
        set s.a = CurrentA
        set s.tr = s.r
        set s.tg = s.g
        set s.tb = s.b
        set s.ta = s.a
        set s.rate = UCTS_RATE
        set s.SAFETY = -1
        call SetUnitVertexColor(u,R2I(CurrentR),R2I(CurrentG),R2I(CurrentB),R2I(CurrentA))
        return s
    endmethod

    //Makes a UCT struct active if applicable. Called automatically by SetInstantRGBA and TargetRGBA.
    //Should only be called directly if someone changes color-related members without using one of
    //the SetInstantRGBA or TargetRGBA methods.
    method UCTAdd takes nothing returns nothing
        if (.r != .tr or .g != .tg or .b != .tb or .a != .ta) and .SAFETY == -1 and .u != null then
            set UCTS_QUANTITY = UCTS_QUANTITY + 1
            set UCTS_ACTIVE[UCTS_QUANTITY] = this
            set .SAFETY = UCTS_QUANTITY
            if UCTS_QUANTITY == 0 then
                call TimerStart(UCTS_TIMER,UCTS_TIMEOUT,true,function UCTSCallback)
            endif
        endif
    endmethod

    //Intended as a replacement for an instant SetUnitVertexColor call if this system is in use, so that the
    //struct will take into account the changes and not immediately change to something else.
    //Boolean targettoo determines whether or not the target values should be changed as well.
    method SetInstantRGBA takes real r, real g, real b, real a, boolean targettoo returns nothing
        set .r = r
        set .g = g
        set .b = b
        set .a = a
        call SetUnitVertexColor(.u,R2I(r),R2I(g),R2I(b),R2I(a))
        if targettoo == true then
            set .tr = r
            set .tg = g
            set .tb = b
            set .ta = a
        else
            call .UCTAdd()
        endif
    endmethod

    //Sets the target values for the unit&#039;s RGBA to approach.
    //If you don&#039;t need to change all the values, just input their struct members into the
    //appropriate slots, ie: call thing.TargetRGBA(225,thing.tg,thing.tb,thing.ta)
    method TargetRGBA takes real r, real g, real b, real a returns nothing
        set .tr = r
        set .tg = g
        set .tb = b
        set .ta = a
        call this.UCTAdd()
    endmethod
    
    //Input a rate in change/second, and this method will scale
    //it and fill in the spot.
    method SetRate takes real r returns nothing
        set .rate = r*UCTS_TIMEOUT
    endmethod
    
    //Detaches the unit from the struct and removes it from active use.
    method onDestroy takes nothing returns nothing
        set .u = null
        if .SAFETY &gt;= 0 then
            set UCTS_ACTIVE[.SAFETY] = UCTS_ACTIVE[UCTS_QUANTITY]
            set UCTS_QUANTITY = UCTS_QUANTITY - 1
        endif
    endmethod
endstruct

//Creates the timer
function Init takes nothing returns nothing
    set UCTS_TIMER = CreateTimer()
endfunction
endlibrary
</i></i>


UCTS is a system that allows relatively easy smooth unit color transitions. UCT structs hold a unit, information for current RGBA (red, green, blue, alpha) values, and information for approaching another set of RGBA values. If the current values and the values to approach are not equal, each value independantly approaches the target value at a specified rate independant to each struct.
UCTS only stores a unit to a struct; it does not store a struct to a unit, so a separate attachment system such as PUI is needed to attach a UCT struct to a unit.

This can be used for anything from unit coloring in spells to terrain camouflage effects.


A few demonstration spells are in the attached UCTS map.
 

Attachments

  • UCTS.w3x
    27.1 KB · Views: 217

BRUTAL

I'm working
Reaction score
118
ou cool ;o
can this constantly change a units colours; like a chameleon?
i made a small thing that does that if your system doesnt do that you should add something like that in

though in the test map i dont get why it turns invisible when they change colours >.>
 

BlackRose

Forum User
Reaction score
239
I like.

But I suggest, in documentation at top, you add in a easy function list like:

call create( u, r, g, b, a)
Easy to CnP.

Useful, but there are others of these types also.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
ou cool ;o
can this constantly change a units colours; like a chameleon?
i made a small thing that does that if your system doesnt do that you should add something like that in

Well, the system isn't made to choose for itself what colors you want the unit to be, but it's easy to program that sort of thing using the system. The dark grass/dirt blending with the five footmen is a chameleon effect.

edit: When you said constantly, did you just mean smooth transitions? Because that's exactly what the system does.

Though, there's also similar but less practical and more flashy things like this:

JASS:

scope cham initializer Init
globals
    private integer i = 0
    private UCT s
endglobals

private function Callback takes nothing returns nothing
    if i == 0 then
        call s.TargetRGBA(255,0,0,255)
        set i = 1
    elseif i == 1 then
        call s.TargetRGBA(0,255,0,255)
        set i = 2
    else
        call s.TargetRGBA(0,0,255,255)
        set i = 0
    endif
endfunction

private function Init takes nothing returns nothing
    local unit u = CreateUnit(Player(0),&#039;hfoo&#039;,100,100,0)
    set s = UCT.create(u,255,255,255,255)
    call s.SetRate(127)
    call TimerStart(CreateTimer(),2,true,function Callback)
endfunction
endscope


I'll stick this in the test map too to demonstrate how simple it is.

though in the test map i dont get why it turns invisible when they change colours >.>
Because I manipulated the alpha values; I felt like demonstrating all four fields of RGBA.

But I suggest, in documentation at top, you add in a easy function list like
Agreed. I'll get right on that.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top