https://wiki.reallusion.com/index.php?title=IC_Python_API:RLPy_RColor&feed=atom&action=history
IC Python API:RLPy RColor - Revision history
2024-03-28T14:14:25Z
Revision history for this page on the wiki
MediaWiki 1.26.2
https://wiki.reallusion.com/index.php?title=IC_Python_API:RLPy_RColor&diff=4502&oldid=prev
Chuck (RL): Created page with "{{TOC}} {{Parent|IC_Python_API:RL_Python_Modules|Modules}} {{last_modified}} == Description == Primary color class that stores data for red (R), green (G), and blue (B). Th..."
2020-04-13T03:27:36Z
<p>Created page with "{{TOC}} {{Parent|IC_Python_API:RL_Python_Modules|Modules}} {{last_modified}} == Description == Primary color class that stores data for red (R), green (G), and blue (B). Th..."</p>
<p><b>New page</b></p><div>{{TOC}}<br />
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}<br />
{{last_modified}}<br />
<br />
== Description ==<br />
<br />
Primary color class that stores data for red (R), green (G), and blue (B). The value stored in [[IC_Python_API:RLPy_RColor|RColor]] ranges from 0 to 1, which represents 0 to 255 in color value. You can swtich between these two representations in different ways; For example, the range of values retrieved by [[#R ( self, args )|R]] is 0 to 1, and the range of values retrieved by [[#Red ( self )|Red]] is 0 to 255. In addition, preset colors are provided for direct usage:<br />
<br />
{| class="wikitable"<br />
!Constant<br />
!Value<br />
|-<br />
|RLPy.RColor.BLACK<br />
|RLPy.RColor(0, 0, 0)<br />
|-<br />
|RLPy.RColor.WHITE<br />
|RLPy.RColor(1, 1, 1)<br />
|-<br />
|RLPy.RColor.RED<br />
|RLPy.RColor(1, 0, 0)<br />
|-<br />
|RLPy.RColor.GREEN<br />
|RLPy.RColor(0, 1, 0)<br />
|-<br />
|RLPy.RColor.BLUE<br />
|RLPy.RColor(0, 0, 1)<br />
|-<br />
|RLPy.RColor.YELLOW<br />
|RLPy.RColor(1, 1, 0)<br />
|-<br />
|RLPy.RColor.CYAN<br />
|RLPy.RColor(0, 1, 1)<br />
|-<br />
|RLPy.RColor.MAGENTA<br />
|RLPy.RColor(1, 0, 1)<br />
|}<br />
<br />
This class also provides conversions to other color formats:<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
# create color<br />
color_red1 = RLPy.RColor(1,0,0,1)<br />
color_red2 = RLPy.RColor()<br />
color_red2.From(255,0,0,255)<br />
color_red3 = RLPy.RColor.RED_ALPHA<br />
<br />
# print color<br />
print( color_red1.R() ) # 1<br />
print( color_red1.Red() ) # 255<br />
<br />
# convert different format<br />
print(hex(color1.ToXRGB())) # 0xff0000<br />
print(hex(color1.ToCOLORREF()))# 0xff<br />
</syntaxhighlight><br />
<br />
See Also: [[IC_Python_API:RLPy_RRgb|RRgb]]<br />
<br />
== Member Functions ==<br />
<br />
=== A ( self, args ) ===<br />
<br />
Get the alpha value of this color (0-1).<br />
<br />
See Also: [[#Alpha ( self )|Alpha]]<br />
<br />
==== Returns ====<br />
:Value for the alpha channel - float [0,1]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(0,0,1,1)<br />
print( color1.A() ) # 1<br />
</syntaxhighlight><br />
<br />
=== AdjustHSBC ( self, fHue, fSaturate, fBrightness, fContrast, bInvert ) ===<br />
<br />
Use HSBC to adjust this color. H stands for hue, S stands for saturation, B for brightness, and C for contrast. The HSBC values range from 0 to 1. If the invert option is true, then the output RGB color will be inverted (1-R, 1-G, 1-B), otherwise known as complementary color.<br />
<br />
See Also: [[#B ( self, args )|B]]<br />
<br />
==== Parameters ====<br />
:'''fHue''' [IN] Hue - float [0,1]<br />
:'''fSaturate''' [IN] Saturate - float [0,1]<br />
:'''fBrightness''' [IN] Brightness - float [0,1]<br />
:'''fContrast''' [IN] Contrast - float [0,1]<br />
:'''bInvert''' [IN] Whether to invert - bool<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor()<br />
color1.AdjustHSBC(0.5, 0.5, 0.5, 0.5, False)<br />
</syntaxhighlight><br />
<br />
=== AdjustRGBA ( self, fRed, fGreen, fBlue, fAlpha, bInvert ) ===<br />
<br />
Use RGBA (red, [[#Green ( self )|Green]], [[#Blue ( self, args )|Blue]], alpha) to adjust this color. The RGBA values range from 0 to 1. When the invert option is true, then the output RGB color will be inverted (1-R, 1-G, 1-B), otherwise known as complementary color.<br />
<br />
==== Parameters ====<br />
:'''fRed''' [IN] Red - float [0,1]<br />
:'''fGreen''' [IN] Green - float [0,1]<br />
:'''fBlue''' [IN] Blue - float [0,1]<br />
:'''fAlpha''' [IN] Alpha - float [0,1]<br />
:'''bInvert''' [IN] Whether to invert - bool<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor()<br />
color1.AdjustRGBA(0.5, 0.5, 0.5, 1.0, False)<br />
</syntaxhighlight><br />
<br />
=== Alpha ( self ) ===<br />
<br />
Get the alpha value of this color (0-255).<br />
<br />
See Also: [[#A ( self, args )|A]]<br />
<br />
==== Returns ====<br />
:Value of the alpha channel - int [0,255]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(0,0,1,1)<br />
print( color1.Alpha() ) # 255<br />
</syntaxhighlight><br />
<br />
=== B ( self, args ) ===<br />
<br />
Get the blue value of this color (0-1).<br />
<br />
See Also: [[#Blue ( self, args )|Blue]]<br />
<br />
==== Returns ====<br />
:Value for the blue channel - float [0,1]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(0,0,1,1)<br />
print( color1.B() ) # 1<br />
</syntaxhighlight><br />
<br />
=== Blue ( self, args ) ===<br />
<br />
Get the blue value of this color (0-255).<br />
<br />
See Also: [[#B ( self, args )|B]]<br />
<br />
==== Returns ====<br />
:Value for the blue channel - float [0,255]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(0,0,1,1)<br />
print( color1.Blue() ) # 255<br />
</syntaxhighlight><br />
<br />
=== From ( self, r, g, b, a ) ===<br />
<br />
Adjust color using 32 bit (0-255).<br />
<br />
==== Parameters ====<br />
:'''r''' [IN] Red value - int [0,255]<br />
:'''g''' [IN] Green value - int [0,255]<br />
:'''b''' [IN] Blue value - int [0,255]<br />
<br />
==== Returns ====<br />
:Changed color - [[IC_Python_API:RLPy_RColor|RColor]]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor()<br />
color1.From(255,0,0,255)<br />
</syntaxhighlight><br />
<br />
=== FromARGB ( self, arg2 ) ===<br />
<br />
Adjust color using ARGB (0xaarrggbb).<br />
<br />
==== Parameters ====<br />
:'''arg2''' [IN] ARGB value.<br />
<br />
==== Returns ====<br />
:Changed color - [[IC_Python_API:RLPy_RColor|RColor]]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor()<br />
color1.FromARGB(int('ff0000ff',16))<br />
</syntaxhighlight><br />
<br />
=== FromCOLORREF ( self, arg2 ) ===<br />
<br />
Adjust color using COLORREF (0xbbggrr).<br />
<br />
==== Parameters ====<br />
:'''arg2''' [IN] COLORREF data<br />
<br />
==== Returns ====<br />
:Changed color - [[IC_Python_API:RLPy_RColor|RColor]]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor()<br />
color1.FromCOLORREF(int('ff0000',16))<br />
</syntaxhighlight><br />
<br />
=== FromHSL( self, fHue, fStaurate, fLevel ) ===<br />
<br />
Adjust color using HSL (Hue, Saturation, Lightness).<br />
<br />
==== Parameters ====<br />
:'''fHue''' [IN] Hue - float [0,1]<br />
:'''fSaturate''' [IN] Saturation - float [0,1]<br />
:'''fLevel''' [IN] Lightness - float [0,1]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor()<br />
color1.FromHSL(0.5,0.5,0.5)<br />
</syntaxhighlight><br />
<br />
=== G ( self, args ) ===<br />
<br />
Get the green value of this color (0-1).<br />
<br />
See Also: [[#Green ( self )|Green]]<br />
<br />
==== Returns ====<br />
:Green value of this color - float [0,1]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(0,1,0,1)<br />
print( color1.G() ) # 1<br />
</syntaxhighlight><br />
<br />
=== GammaCorrect ( self, fGamma ) ===<br />
<br />
Output this color with gamma correction.<br />
<br />
==== Returns ====<br />
:Gamma corrected color - [[IC_Python_API:RLPy_RColor|RColor]]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(0.5,0,0,1)<br />
print( color1.GammaCorrect() ) # RGBA(0.73,0,0,1)<br />
</syntaxhighlight><br />
<br />
=== Green ( self ) ===<br />
<br />
Get the green value of this color (0-255).<br />
<br />
See Also: [[#G ( self, args )|G]]<br />
<br />
==== Returns ====<br />
:Green value of this color (0-255) - int<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(0,1,0,1)<br />
print( color1.Green() ) # 1<br />
</syntaxhighlight><br />
<br />
=== Normalize( self ) ===<br />
<br />
Normalize RGB values so that their sum equals 1.<br />
<br />
==== Returns ====<br />
:Normalized color - [[IC_Python_API:RLPy_RColor|RColor]]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(0,1,0,1)<br />
color1.Normalize() # (0, 0.5, 0, 0.5)<br />
</syntaxhighlight><br />
<br />
=== R ( self, args ) ===<br />
<br />
Get the red value of this color (0-1).<br />
<br />
See Also: [[#Red ( self )|Red]]<br />
<br />
==== Returns ====<br />
:Red value of this color - float [0,1]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(1,0,0,1)<br />
print( color1.R() ) # 1<br />
</syntaxhighlight><br />
<br />
=== Red ( self ) ===<br />
<br />
Get the red value of this color (0-255).<br />
<br />
See Also: [[#R ( self, args )|R]]<br />
<br />
==== Returns ====<br />
:Red value of this color - int [0,255]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(1,0,0,1)<br />
print( color1.Red() ) # 255<br />
</syntaxhighlight><br />
<br />
=== Saturate ( self ) ===<br />
<br />
Clamp the RGB values to a range of 0 and 1. Values under 0 will become 0, and values over 1 will become 1.<br />
<br />
==== Returns ====<br />
:This color saturated - [[IC_Python_API:RLPy_RColor|RColor]]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(1.2,-0.3,0.5, 1.0)<br />
color1.Saturate() # (1, 0, 0.5, 1.0)<br />
</syntaxhighlight><br />
<br />
=== ToARGB ( self ) ===<br />
<br />
Output ARGB data from this color (0xaarrggbb).<br />
<br />
See Also: [[#FromARGB ( self, arg2 )|FromARGB]]<br />
<br />
==== Returns ====<br />
:ARGB color data - int<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(0, 0, 1, 1)<br />
print( int(color1.ToARGB()) ) # 0xffff0000<br />
</syntaxhighlight><br />
<br />
=== ToARGB ( self ) ===<br />
<br />
Output ARGB data from this color (0xaarrggbb).<br />
<br />
==== Returns ====<br />
:ARGB color data - int<br />
<br />
See Also: [[#FromARGB ( self, arg2 )|FromARGB]]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(0, 0, 1, 1)<br />
print( int(color1.ToARGB()) ) # 0xffff0000<br />
</syntaxhighlight><br />
<br />
=== ToCOLORREF ( self ) ===<br />
<br />
Output COLORREF data from this color (0xbbggrr). <br />
<br />
See Also: [[#FromCOLORREF ( self, arg2 )|FromCOLORREF]]<br />
<br />
==== Returns ====<br />
:COLORREF color data - int<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(0, 0, 1, 1)<br />
print( int(color1.ToCOLORREF()) ) # 0xff0000<br />
</syntaxhighlight><br />
<br />
=== ToGrayScale ( self ) ===<br />
<br />
Output grayscale data from this color (0-1). <br />
<br />
==== Returns ====<br />
:Grayscale data - float [0,1]<br />
<br />
<syntaxhighlight lang="python" line='line'><br />
color1 = RLPy.RColor(0, 0, 1, 1)<br />
print( color1.ToGrayScale() ) # 0.11400000005960464<br />
</syntaxhighlight></div>
Chuck (RL)