System Fade Unit System

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
=============================================
     _______   __    __    ______
    |   ____| |  |  |  |  / _____\
    |  |__    |  |  |  |  | |
    |   __|   |  |  |  |  | |____
    |  |      |  |  |  |  \____  \
    |  |      \  |__|  /   ____| |
    |__|       \______/   \______/
     
    Fade Unit System ~~v1.0.0~~
    
    This system fades units color over time.
==============================================
    
    Functions provided :
    Fade.start(whichunit, r1, g1, b1, a1, r2, g2, b2, a2, duration) -> Fade index
    Fade.stop(Fade index, WantTargetColor) (If you want to stop fading instantly, use this) =)
    
    Details on parameters :
        Real parameters ->
            r1 -> Original Red Color Index
            r2 -> Target Red Color Index
            g1 -> Original Green Color Index
            g2 -> Target Green Color Index
            b1 -> Original Blue Color Index
            b2 -> Target Blue Color Index
            a1 -> Original Alpha Index
            a2 -> Target Alpha Index
    
        Boolean parameters ->
            WantTargetColor -> Instantly set target color index to unit after stop fading
            
    Pros :
    Uses real on color index calculations, therefore the color generated is more smooth.
    Efficient
    
    Cons :
    Many parameters are needed to call the function.
    
    Requires :
    T32
    Jasshelper 0.9.K.2 or newer (For vJass version)
    Jasshelper 0.9.Z.2 or newer (For Zinc version)


T32's Link here : Click Me!

vJass version :
JASS:
library FUS requires T32
    
    struct Fade
        private static thistype d
        private real red
        private real green
        private real blue
        private real alpha
        private real tred
        private real tgreen
        private real tblue
        private real talpha
        private real cred
        private real cgreen
        private real cblue
        private real calpha
        //Reals for reality =)
        private integer ticks
        private unit targ
        private boolean wanStop
        
        private method periodic takes nothing returns boolean
            if this.ticks > 0 and not this.wanStop then
                set this.ticks = this.ticks - 1
                set this.cred = this.cred + this.red
                set this.cgreen = this.cgreen + this.green
                set this.cblue = this.cblue + this.blue
                set this.calpha = this.calpha + this.alpha
                call SetUnitVertexColor(this.targ,R2I(this.cred),R2I(this.cgreen),R2I(this.cblue),R2I(this.calpha))
                return false
            endif
            call this.destroy()
            return true
        endmethod
        
        implement T32
        
        static method start takes unit whichUnit, integer oriRed, integer oriGreen, integer oriBlue, integer oriAlpha, integer targRed, integer targGreen, integer targBlue, integer targAlpha, real duration returns thistype
            set thistype.d = thistype.allocate()
            set thistype.d.targ = whichUnit
            set thistype.d.cred = oriRed
            set thistype.d.cgreen = oriGreen
            set thistype.d.cblue = oriBlue
            set thistype.d.calpha = oriAlpha
            set thistype.d.tred = targRed
            set thistype.d.tgreen = targGreen
            set thistype.d.tblue = targBlue
            set thistype.d.talpha = targAlpha
            set thistype.d.ticks = R2I(duration / T32_PERIOD)
            set thistype.d.red = (thistype.d.tred - thistype.d.cred) / thistype.d.ticks
            set thistype.d.green = (thistype.d.tgreen - thistype.d.cgreen) / thistype.d.ticks
            set thistype.d.blue = (thistype.d.tblue - thistype.d.cblue) / thistype.d.ticks
            set thistype.d.alpha = (thistype.d.talpha - thistype.d.calpha) / thistype.d.ticks
            set thistype.d.wanStop = false
            call SetUnitVertexColor(whichUnit,oriRed,oriGreen,oriBlue,oriAlpha)
            call thistype.d.startPeriodic()
            return thistype.d
        endmethod   
            
        static method stop takes thistype whichInstance, boolean toTargetColor returns nothing
            set whichInstance.wanStop = true
            if toTargetColor then
                call SetUnitVertexColor(whichInstance.targ,R2I(whichInstance.tred),R2I(whichInstance.tgreen),R2I(whichInstance.tblue),R2I(whichInstance.talpha))
            endif
        endmethod 

    endstruct
endlibrary


Zinc Version:
JASS:
//! zinc
library UFS requires T32
{
    public struct Fade
    {
        
        private 
        {
        real red, green, blue, alpha, tred, tgreen, tblue, talpha, cred, cblue, cgreen, calpha;
        unit targ;
        integer ticks;
        boolean wantStop;
        static thistype d;
        }
        
        method periodic() -> boolean
        {
            while (this.ticks > 0)
            {
                while (this.wantStop == false)
                {
                    this.ticks = this.ticks - 1;
                    this.cred = this.cred + this.red;
                    this.cgreen = this.cgreen + this.green;
                    this.cblue = this.cblue + this.blue;
                    this.calpha = this.calpha + this.alpha;
                    SetUnitVertexColor(this.targ,R2I(this.cred),R2I(this.cgreen),R2I(this.cblue),R2I(this.calpha));
                    return false;
                }
            }
            this.destroy();
            return true;
        }

        implement T32;
        
        static method start (unit whichUnit, integer oriRed, integer oriGreen, integer oriBlue, integer oriAlpha, integer targRed, integer targGreen, integer targBlue, integer targAlpha, real duration) -> thistype
        {
            thistype.d = thistype.allocate();
            thistype.d.targ = whichUnit;
            thistype.d.cred = oriRed;
            thistype.d.cgreen = oriGreen;
            thistype.d.cblue = oriBlue;
            thistype.d.calpha = oriAlpha;
            thistype.d.tred = targRed;
            thistype.d.tgreen = targGreen;
            thistype.d.tblue = targBlue;
            thistype.d.talpha = targAlpha;
            thistype.d.ticks = R2I(duration / T32_PERIOD);
            thistype.d.red = (thistype.d.tred - thistype.d.cred) / thistype.d.ticks;
            thistype.d.green = (thistype.d.tgreen - thistype.d.cred) / thistype.d.ticks;
            thistype.d.blue = (thistype.d.tblue - thistype.d.cblue) / thistype.d.ticks;
            thistype.d.alpha = (thistype.d.talpha - thistype.d.calpha) / thistype.d.ticks;
            thistype.d.wantStop = false;
            SetUnitVertexColor(whichUnit,oriRed,oriGreen,oriBlue,oriAlpha);
            thistype.d.startPeriodic();
            return thistype.d;
        }
        
        static method stop (thistype whichInstance, boolean toTargetColor)
        {
            whichInstance.wantStop = true;
            if (toTargetColor == true)
            {
                SetUnitVertexColor(whichInstance.targ, R2I(whichInstance.tred) , R2I(whichInstance.tgreen) , R2I(whichInstance.tblue), R2I(whichInstance.talpha));
            }
        }

    }
}
//! endzinc


There are 2 unit fading systems approved at here. But this is more efficient. :thup:
 

Romek

Super Moderator
Reaction score
964
> There are 2 unit fading systems approved at here. But mine is more efficient.
Why don't you post in those threads, and tell the creators what they could improve to increase efficiency? :thdown:

Why is 'stop' static?

I also don't think systems this simple should use acronyms.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Why is 'stop' static?
Fade.start()
Fade.stop()
Nicer functions' name. lol :D

Why don't you post in those threads, and tell the creators what they could improve to increase efficiency?
Those systems do fading in different way.

Uberplayer's fade system only fades alpha channel.

Larcenist's FadeUnitTimed is kinda weird.
4) 2, true, 4. The first number here, 2, is how many seconds it will take for the unit to fade from (in my case) 0 to 100%. The next value, true, is a boolean to tell the system if you want the unit to regain it's starting transparency after the fade. The last number is the time it takes to regain the starting transparency (4 seconds to go from 100% to 0% transparency in my case).
= =?

So, I created this Fade Unit System to ease the fading and providing an efficient script to users.
 
Reaction score
456
My Fade System can be dropped off. I don't plan updating it, because I personally think this kind of stuff is useless :).
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, not to be selfish here, but isn't this almost the same (Apart from you having alot more members (Which are a bit unecessary imho)) as in my thread here:
http://www.thehelper.net/forums/showthread.php?t=137304

Why not help me out there, instead if you think it lacks features, since mine already has more features than yours ? :eek:

(Looks like this atm:)
JASS:
library SmoothUnitMod requires T32, UnitAppearance

    struct SmoothScaleChange
    
        //private code userFunc
        private integer ticks
        
        private real increment
        
        private unit u
        
        private method periodic takes nothing returns boolean
            set this.ticks = this.ticks - 1
        
            call ModifyUnitScale( this.u, this.increment )
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].scale ) )
            
            if this.ticks <= 0 then
                call this.destroy()
                
                return true
            endif
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Scaler, real Time, real scaleMod, code userFunc returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Scaler
            //set this.userFunc = userFunc
            set this.increment = ( ( scaleMod * T32_PERIOD ) / Time )
            set this.ticks = R2I( scaleMod / this.increment ) // How many times the timer must fire...
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function ScaleSimple takes unit Scaler, real Time, real scaleMod returns SmoothScaleChange
        return SmoothScaleChange.create( Scaler, Time, scaleMod, null )
    endfunction
    
    function ScaleEx takes unit Scaler, real Time, real scaleMod, code userFunc returns SmoothScaleChange
        return SmoothScaleChange.create( Scaler, Time, scaleMod, userFunc )
    endfunction
    
    function GetUnitScale takes unit u returns real
        return Appearance[ u ].scale
    endfunction
    
    struct SmoothColorChange
    
        private integer ticks
        
        private real rincrement
        private real gincrement
        private real bincrement
        private real increment
        
        private unit u
        
        private method periodic takes nothing returns boolean
            set this.ticks = this.ticks - 1
        
            call ModifyUnitVertexColor( this.u, R2I( this.rincrement ), R2I( this.gincrement ), R2I( this.bincrement ), R2I( this.increment ) )
            
            debug call BJDebugMsg( R2S( Appearance[this.u].alpha ) )
            
            if this.ticks <= 0 then
                call this.destroy()
                
                return true
            endif
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Fader, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Fader
            set this.increment = ( ( alphaMod * T32_PERIOD ) / Time )
            set this.rincrement = ( ( redMod * T32_PERIOD ) / Time )
            set this.gincrement = ( ( greenMod * T32_PERIOD ) / Time )
            set this.bincrement = ( ( blueMod * T32_PERIOD ) / Time )
            set this.ticks = R2I( alphaMod / this.increment )
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function FadeSimple takes unit Fader, real Time, real alphaMod returns SmoothColorChange
        return SmoothColorChange.create( Fader, Time, 0., 0., 0., alphaMod )
    endfunction
    
    function FadeEx takes unit Fader, real Time, real redMod, real greenMod, real blueMod, real alphaMod returns SmoothColorChange
        return SmoothColorChange.create( Fader, Time, redMod, greenMod, blueMod, alphaMod )
    endfunction
    
    function GetUnitAlpha takes unit u returns integer
        return Appearance[ u ].alpha
    endfunction

    function GetUnitRedColor takes unit u returns integer
        return Appearance[ u ].red
    endfunction
    
    function GetUnitGreenColor takes unit u returns integer
        return Appearance[ u ].green
    endfunction
    
    function GetUnitBlueColor takes unit u returns integer
        return Appearance[ u ].blue
    endfunction
    
    struct SmoothTSChange
    
        //private code userFunc
        private integer ticks
        
        private real increment
        
        private unit u
        
        private method periodic takes nothing returns boolean
            set this.ticks = this.ticks - 1
        
            call ModifyUnitTimeScale( this.u, this.increment )
            
            debug call BJDebugMsg( R2S( Appearance[ this.u ].timescale ) )
            
            if this.ticks <= 0 then
                call this.destroy()
                
                return true
            endif
            
            return false
        endmethod
        
        implement T32
        
        static method create takes unit Timer, real Time, real timescaleMod, code userFunc returns thistype
            local thistype this = thistype.allocate()
            
            set this.u = Timer
            //set this.userFunc = userFunc
            set this.increment = ( ( timescaleMod * T32_PERIOD ) / Time )
            set this.ticks = R2I( timescaleMod / this.increment ) // How many times the timer must fire...
            
            call this.startPeriodic()
            
            return this
        endmethod
        
    endstruct
    
    function TimeScaleChange takes unit Timer, real Time, real timescaleMod returns SmoothTSChange
        return SmoothTSChange.create( Timer, Time, timescaleMod, null )
    endfunction
    
    function TimeScaleChangeEx takes unit Timer, real Time, real timescaleMod, code userFunc returns SmoothTSChange
        return SmoothTSChange.create( Timer, Time, timescaleMod, userFunc )
    endfunction
    
    function GetUnitTimeScale takes unit u returns real
        return Appearance[ u ].timescale
    endfunction

endlibrary
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Your system does more stuffs. I can help you if possible. :)

But the aim of this system is providing an easy and lite fading interface for everyone. =)
 
Reaction score
91
> because I personally think this kind of stuff is useless
Have to agree with this one, you'll probably be using fading in 1-2 spells so coding it yourself is better...
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
How the heck are you expected to know the initial colour values? Lol.
So I added the value for users to set. lol.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top