Legacy:Color Operators: Difference between revisions

From Unreal Wiki, The Unreal Engine Documentation Site
No edit summary
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
This is an example of [[Legacy:Scripting Operators|Scripting Operators]].
Useful [[Legacy:Operators|operators]] for the '''color''' [[Legacy:Variable Type|Variable Type]]. This is an example of [[Legacy:Scripting Operators|Scripting Operators]].


See also [[Legacy:RGB To HLS Conversion|RGB to HLS conversion]] and [[Legacy:HLS To RGB Conversion|HLS to RGB conversion]].
See also [[Legacy:RGB To HLS Conversion|RGB to HLS conversion]] and [[Legacy:HLS To RGB Conversion|HLS to RGB conversion]].
Line 131: Line 131:
}
}
</uscript>
</uscript>
==Related Topics ==
* [[Legacy:Operators|Operators]]

Latest revision as of 11:37, 15 March 2004

Useful operators for the color Variable Type. This is an example of Scripting Operators.

See also RGB to HLS conversion and HLS to RGB conversion.

Due to the lack of any color operators, let's make a few:

<uscript> // Lighten color by 1 static final preoperator color ++ ( out color A ) {

 A.R++;
 A.G++;
 A.B++;
 return A;

} // Darken color by 1 static final preoperator color -- ( out color A ) {

 A.R--;
 A.G--;
 A.B--;
 return A;

}

// Postoperator version static final postoperator color ++ ( out color A ) {

 local color Copy;
 Copy = A;
 A.R++;
 A.G++;
 A.B++;
 return Copy;

}

// Postoperator version static final postoperator color -- ( out color A ) {

 local color Copy;
 Copy = A;
 A.R--;
 A.G--;
 A.B--;
 return Copy;

}

// Remember that averaging operator we just used? Now it's suddenly useful, so I've copied it into here final operator(18) int : ( int A, int B ) {

 return (A + B) / 2;

}

// Interpolate 2 colors static final operator(22) color Mix ( color A, color B ) {

 local Color Result;
 Result.R = A.R : B.R;
 Result.G = A.G : B.G;
 Result.B = A.B : B.B;
 return Result;

}

// UT Provides a * operator for colors, but no /. Ramp a color by a float static final operator(16) color / ( color A, float B ) {

 local Color Result;
 Result.R = A.R / B;
 Result.G = A.G / B;
 Result.B = A.B / B;
 return Result;

}

// Same thing, but this one affects the color static final operator(34) color /= ( out color A, float B ) {

 A = A / B;
 return A;

}

// UT Provides *, not *=, so let's implement it static final operator(34) color *= ( out color A, float B ) {

 A = A * B;
 return A;

}

// Add a byte value to each component static final operator(20) color + ( color A, byte B ) {

 local Color Result;
 Result.R = A.R + B;
 Result.G = A.G + B;
 Result.B = A.B + B;
 return Result;

}

// Subtract a byte value to each component static final operator(20) color - ( color A, byte B ) {

 local Color Result;
 Result.R = A.R - B;
 Result.G = A.G - B;
 Result.B = A.B - B;
 return Result;

}

// Out versions of the operators static final operator(34) color += ( out color A, byte B ) {

 A = A + B;
 return A;

}

static final operator(34) color -= ( out color A, byte B ) {

 A = A - B;
 return A;

}

// Out version of the operator UT provides static final operator(34) color += ( out color A, color B ) {

 A = A + B;
 return A;

}

static final operator(34) color -= ( out color A, color B ) {

 A = A - B;
 return A;

} </uscript>

Related Topics