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: