Difference between revisions of "IC Python API:RLPy RRgb"

From Reallusion Wiki!
Jump to: navigation, search
m
m
Line 1: Line 1:
 
{{TOC}}
 
{{TOC}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
==Detailed Description==
+
{{last_modified}}
This class represent the color data RGB.
+
 
==Operators==
+
== Description ==
This class supports the following operators:
+
 
{| class="wikitable"
+
Primary color class that stores data for red (R), green (G), and blue (B).  The value stored in RRgb 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 RRgb.R() is 0 to 1, and the range of values retrieved by RRgb.Red() is 0 to 255.  In addition, preset colors are provided for direct usage:
!Member
+
 
!Operation
+
{|class="wikitable"
!Syntax
+
!Constant
!Description
+
!Value
!Example
+
 
|-
 
|-
! scope="row" | __add__
+
|RLPy.RRgb.BLACK
| Addition
+
|RLPy.RRgb(0, 0, 0)
| a + b
+
| Adds values on either side of the operator.
+
| a + b = 30
+
 
|-
 
|-
! scope="row" | __sub__
+
|RLPy.RRgb.WHITE
| Subtraction
+
|RLPy.RRgb(1, 1, 1)
| a - b
+
| Subtracts right hand operand from left hand operand.
+
| a – b = -10
+
 
|-
 
|-
! scope="row" | __mul__
+
|RLPy.RRgb.RED
| Multiplication
+
|RLPy.RRgb(1, 0, 0)
| a * b
+
| Multiplies values on either side of the operator.
+
| a * b = 200
+
 
|-
 
|-
! scope="row" | __truediv__
+
|RLPy.RRgb.GREEN
| Division
+
|RLPy.RRgb(0, 1, 0)
| a / b
+
| Divides left hand operand by right hand operand.
+
| b / a = 2
+
 
|-
 
|-
! scope="row" | __neg__
+
|RLPy.RRgb.BLUE
| Negation
+
|RLPy.RRgb(0, 0, 1)
| -a
+
| Return the value negated.
+
| a = -b
+
 
|-
 
|-
! scope="row" | __pos__
+
|RLPy.RRgb.YELLOW
| Positive
+
|RLPy.RRgb(1, 1, 0)
| +a
+
| Return value positive.
+
| a = +b
+
 
|-
 
|-
! scope="row" | __eq__
+
|RLPy.RRgb.CYAN
| Equality
+
|RLPy.RRgb(0, 1, 1)
| a == b
+
| If the values of two operands are equal, then the condition becomes true.
+
| (a == b) is not true.
+
 
|-
 
|-
! scope="row" | __ne__
+
|RLPy.RRgb.MAGENTA
| Difference
+
|RLPy.RRgb(1, 0, 1)
| a != b
+
| If values of two operands are not equal, then condition becomes true.
+
| (a != b) is true.
+
|-
+
! scope="row" | __lt__
+
| Less Than
+
| a < b
+
| If the value of left operand is less than the value of right operand, then condition becomes true.
+
| (a < b) is true.
+
|-
+
! scope="row" | __iadd__
+
| Addition (Inplace)
+
| a += b
+
| It adds right operand to the left operand and assign the result to left operand.
+
| c += a is equivalent to c = c + a
+
|-
+
! scope="row" | __isub__
+
| Subtraction (Inplace)
+
| a -= b
+
| It subtracts right operand from the left operand and assign the result to left operand.
+
| c -= a is equivalent to c = c - a
+
|-
+
! scope="row" | __imul__
+
| Multiply (Inplace)
+
| a *= b
+
| It multiplies right operand with the left operand and assign the result to left operand.
+
| c *= a is equivalent to c = c * a
+
|-
+
! scope="row" | __itruediv__
+
| Divide (Inplace)
+
| a /= b
+
| It divides left operand with the right operand and assign the result to left operand.
+
| c /= a is equivalent to c = c / ac /= a is equivalent to c = c / a
+
 
|}
 
|}
==Member Functions==
+
 
===B===
+
RRgb does not include alpha data.  Use [https://wiki.reallusion.com/IC_Python_API:RLPy_RColor RLPy.RColor()] instead if alpha channel is needed.  This class also provides conversions to other color formats:
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.B ( self, args )
+
# create color
 +
color_red1 = RLPy.RRgb(1, 0, 0)
 +
color_red2 = RLPy.RRgb()
 +
color_red2.From(255, 0, 0)
 +
color_red3 = RLPy.RRgb.RED
 +
 +
# print color
 +
print( color_red1.R() )        # 1
 +
print( color_red1.Red() )      # 255
 +
 +
# convert different format
 +
print(hex(color1.ToXRGB()))    # 0xff0000
 +
print(hex(color1.ToCOLORREF())) # 0xff
 
</syntaxhighlight>
 
</syntaxhighlight>
Get the value of the color-Blue.
+
 
====Returns====
+
See Also: [https://wiki.reallusion.com/IC_Python_API:RLPy_RColor RLPy.RColor()]
<div style="margin-left: 2em;">The value of the color-Blue - float
+
 
</div>
+
== Member Functions ==
-----
+
 
===Blue===
+
=== B ( self, args ) ===
 +
 
 +
Get the blue value of this color (0 to 1).
 +
 
 +
See Also: [[#RLPy.RRgb.Blue | RLPy.RRgb.Blue()]]
 +
 
 +
==== Returns ====
 +
:Value for the blue channel (0 to 1) - float
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.Blue ( self )
+
color1 = RLPy.RRgb(0, 0, 1)
 +
print(color1.B())              # 1
 
</syntaxhighlight>
 
</syntaxhighlight>
Get the value of the color-Blue.
+
 
====Returns====
+
=== Blue ( self ) ===
<div style="margin-left: 2em;">The value of the color-Blue(value: 0~255) - int
+
 
</div>
+
Get the blue value of this color (0 to 255).
-----
+
 
===From===
+
See Also: [[#RLPy.RRgb.B | RLPy.RRgb.B()]]
 +
 
 +
==== Returns ====
 +
:Value for the blue channel (0-255) - int
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.From ( self, r, g, b )
+
color1 = RLPy.RRgb(0, 0, 1)
 +
print(color1.Blue())           # 255
 
</syntaxhighlight>
 
</syntaxhighlight>
Convert unsigned char rgb data to CRgb.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''r''' [IN] the unsigned char value of red - string
+
=== From ( self, r, g, b ) ===
  
'''g''' [IN] the unsigned char value of green - string
+
Change this color using 32 bit format (0 to 255).
 +
 
 +
==== Parameters ====
 +
:'''r''' [IN] Red value (0-255) - int
 +
:'''g''' [IN] Green value (0-255) - int
 +
:'''b''' [IN] Blue value (0-255) - int
 +
 
 +
==== Returns ====
 +
:Newly set RRgb - RLPy.RRgb
  
'''b''' [IN] the unsigned char value of blue - string
 
</div>
 
====Returns====
 
<div style="margin-left: 2em;">The CRgb data - RLPy.RRgb
 
</div>
 
-----
 
===FromCOLORREF===
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.FromCOLORREF ( self, arg2 )
+
color1 = RLPy.RRgb()
 +
color1.From(255, 0, 0)
 
</syntaxhighlight>
 
</syntaxhighlight>
Convert COLORREF data to CRgb.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''[IN]''' the unsigned long COLORREF value.
+
=== FromCOLORREF ( self, arg2 ) ===
</div>
+
 
====Returns====
+
Change this color using COLORREF format (0xbbggrr).
<div style="margin-left: 2em;">The CRgb data - RLPy.RRgb
+
 
</div>
+
See Also: [[#RLPy.RRgb.ToCOLORREF | RLPy.RRgb.ToCOLORREF()]]
-----
+
 
===FromXRGB===
+
==== Parameters ====
 +
:'''arg2''' [IN] COLORREF data
 +
 
 +
==== Returns ====
 +
:Newly set RRgb - RLPy.RRgb
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.FromXRGB ( self, arg2 )
+
color_red2 = RLPy.RRgb()
 +
color_red2.FromCOLORREF(int(‘ff0000’, 16))
 
</syntaxhighlight>
 
</syntaxhighlight>
Convert XRGB to CRgb.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''[IN]''' the unsigned long XRGB value.
+
=== FromXRGB ( self, arg2 ) ===
</div>
+
 
====Returns====
+
Assign this color using hexadecimal format (0xrrggbb).
<div style="margin-left: 2em;">Return the CRgb data - RLPy.RRgb
+
 
</div>
+
See Also: [[#RLPy.RRgb.ToXRGB | RLPy.RRgb.ToXRGB()]]
-----
+
 
===G===
+
==== Parameters ====
 +
:'''arg2''' [IN] RGB hexadecimal value - HEX
 +
 
 +
==== Returns ====
 +
:Newly set RRgb - RLPy.RRgb
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.G ( self, args )
+
color_red2 = RLPy.RRgb()
 +
color_red2.FromXRGB(int(‘0000ff’, 16))
 
</syntaxhighlight>
 
</syntaxhighlight>
Get the value of the color-Green.
+
 
====Returns====
+
=== G ( self, args ) ===
<div style="margin-left: 2em;">The value of the color-Green - float
+
 
</div>
+
Get the green value of this color (0-1).
-----
+
 
===Green===
+
See Also: [[#RLPy.RRgb.Green | RLPy.RRgb.Green()]]
 +
 
 +
==== Returns ====
 +
:Green value of this color - float (0-1)
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.Green ( self )
+
color1 = RLPy.RRgb(0, 1, 0)
 +
print(color1.G())              # 1
 
</syntaxhighlight>
 
</syntaxhighlight>
Get the value of the color-Green.
+
 
====Returns====
+
=== Green ( self ) ===
<div style="margin-left: 2em;">The value of the color-Green(value: 0~255) - int
+
 
</div>
+
Get the green value of this color (0-255).
-----
+
 
===Normalize===
+
See Also: [[#RLPy.RRgb.G | RLPy.RRgb.G()]]
 +
 
 +
==== Returns ====
 +
:Green value of this color (0-255) - int
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.Normalize ( self )
+
color1 = RLPy.RRgb(0, 1, 0)
 +
print(color1.Green())          # 255
 
</syntaxhighlight>
 
</syntaxhighlight>
Normalizes this rgb vector.
+
 
====Returns====
+
=== Normalize ( self ) ===
<div style="margin-left: 2em;">The normalized rgb vector - RLPy.RRgb
+
 
</div>
+
Normalize RGB values so that their sum equals 1.
-----
+
 
===R===
+
==== Returns ====
 +
:Normalized RRgb - RLPy.RRgb
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.R ( self, args )
+
color1 = RLPy.RRgb(1, 1, 0)
 +
color1.Normalize()              # (0.5, 0.5, 0)
 
</syntaxhighlight>
 
</syntaxhighlight>
Get the value of the color-Red.
+
 
====Returns====
+
=== R ( self, args ) ===
<div style="margin-left: 2em;">The value of the color-Red - float
+
 
</div>
+
Get the red value of this color (0-1).
-----
+
 
===Red===
+
See Also: [[#RLPy.RRgb.Red | RLPy.RRgb.Red()]]
 +
 
 +
==== Returns ====
 +
:Red value of this color (0-1) - float
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.Red ( self )
+
color1 = RLPy.RRgb(1, 0, 0)
 +
print(color1.R())              # 1
 
</syntaxhighlight>
 
</syntaxhighlight>
Get the value of the color-Red.
+
 
====Returns====
+
=== Red ( self ) ===
<div style="margin-left: 2em;">The value of the color-Red(value: 0~255) - int
+
 
</div>
+
Get the red value of this color (0-255).
-----
+
 
===Saturate===
+
See Also: [[#RLPy.RRgb.Red | RLPy.RRgb.R()]]
 +
 
 +
==== Returns ====
 +
:Red value of this color (0-255) - int
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.Saturate ( self )
+
color1 = RLPy.RRgb(1, 0, 0)
 +
print(color1.Red())            # 255
 
</syntaxhighlight>
 
</syntaxhighlight>
Saturates this rgb vector.
+
 
====Returns====
+
=== Saturate ( self ) ===
<div style="margin-left: 2em;">The saturated rgb vector - RLPy.RRgb
+
 
</div>
+
Clamp the RGB values to a range of 0 and 1.  Values under 0 will become 0, and values over 1 will become 1.
-----
+
 
===ToCOLORREF===
+
==== Returns ====
 +
:This color saturated (RRgb) - RLPy.RRgb
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.ToCOLORREF ( self )
+
color1 = RLPy.RRgb(1.2, -0.3, 0.5)
 +
color1.Saturate()              # (1, 0, 0.5)
 
</syntaxhighlight>
 
</syntaxhighlight>
Convert CRgb to COLORREF.
+
 
====Returns====
+
=== ToCOLORREF ( self ) ===
<div style="margin-left: 2em;">The COLORREF data - int
+
 
</div>
+
Output COLORREF data from this color (0xbbggrr).
-----
+
 
===ToVector3f===
+
See Also: [[#RLPy.RRgb.FromCOLORREF | RLPy.RRgb.FromCOLORREF()]]
 +
 
 +
==== Returns ====
 +
:COLORREF data - int
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.ToVector3f ( self )
+
color1 = RLPy.RRgb(0, 0, 1)
 +
print(int(color1.ToCOLORREF()))          # 0xff0000
 
</syntaxhighlight>
 
</syntaxhighlight>
Returns CRgb to Vector3f.
+
 
====Returns====
+
=== ToVector3f ( self ) ===
<div style="margin-left: 2em;">Return the Vector3f data - RLPy.RVector3f
+
 
</div>
+
Output 3D vector data from this color (RVector3f)
-----
+
 
===ToXRGB===
+
==== Returns ====
 +
:3D vector color data - RLPy.RVector3f
 +
 
 +
<syntaxhighlight lang="Python">
 +
color1 = RLPy.RRgb(0, 0, 1)
 +
print(color1.ToVector3f())
 +
</syntaxhighlight>
 +
 
 +
=== ToXRGB ( self ) ===
 +
 
 +
Output hexadecimal data from this color (0xrrggbb)
 +
 
 +
See Also: [[#RLPy_RRgb#FromXRGB | RLPy.RRgb.FromXRGB()]]
 +
 
 +
==== Returns ====
 +
:Hexadecimal color data - int
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RRgb.ToXRGB ( self )
+
color1 = RLPy.RRgb(0, 0, 1)
 +
print(int(color1.ToXRGB()))              # 0xff
 
</syntaxhighlight>
 
</syntaxhighlight>
Convert CRgb to XRGB.
 
====Returns====
 
<div style="margin-left: 2em;">The XRGB data - int
 
</div>
 

Revision as of 01:09, 26 February 2020

Main article: Modules.
Last modified: 02/26/2020

Description

Primary color class that stores data for red (R), green (G), and blue (B). The value stored in RRgb 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 RRgb.R() is 0 to 1, and the range of values retrieved by RRgb.Red() is 0 to 255. In addition, preset colors are provided for direct usage:

Constant Value
RLPy.RRgb.BLACK RLPy.RRgb(0, 0, 0)
RLPy.RRgb.WHITE RLPy.RRgb(1, 1, 1)
RLPy.RRgb.RED RLPy.RRgb(1, 0, 0)
RLPy.RRgb.GREEN RLPy.RRgb(0, 1, 0)
RLPy.RRgb.BLUE RLPy.RRgb(0, 0, 1)
RLPy.RRgb.YELLOW RLPy.RRgb(1, 1, 0)
RLPy.RRgb.CYAN RLPy.RRgb(0, 1, 1)
RLPy.RRgb.MAGENTA RLPy.RRgb(1, 0, 1)

RRgb does not include alpha data. Use RLPy.RColor() instead if alpha channel is needed. This class also provides conversions to other color formats:

# create color
color_red1 = RLPy.RRgb(1, 0, 0)
color_red2 = RLPy.RRgb()
color_red2.From(255, 0, 0)
color_red3 = RLPy.RRgb.RED
 
# print color
print( color_red1.R() )         # 1
print( color_red1.Red() )       # 255
 
# convert different format
print(hex(color1.ToXRGB()))     # 0xff0000
print(hex(color1.ToCOLORREF())) # 0xff

See Also: RLPy.RColor()

Member Functions

B ( self, args )

Get the blue value of this color (0 to 1).

See Also: RLPy.RRgb.Blue()

Returns

Value for the blue channel (0 to 1) - float
color1 = RLPy.RRgb(0, 0, 1)
print(color1.B())               # 1

Blue ( self )

Get the blue value of this color (0 to 255).

See Also: RLPy.RRgb.B()

Returns

Value for the blue channel (0-255) - int
color1 = RLPy.RRgb(0, 0, 1)
print(color1.Blue())            # 255

From ( self, r, g, b )

Change this color using 32 bit format (0 to 255).

Parameters

r [IN] Red value (0-255) - int
g [IN] Green value (0-255) - int
b [IN] Blue value (0-255) - int

Returns

Newly set RRgb - RLPy.RRgb
color1 = RLPy.RRgb()
color1.From(255, 0, 0)

FromCOLORREF ( self, arg2 )

Change this color using COLORREF format (0xbbggrr).

See Also: RLPy.RRgb.ToCOLORREF()

Parameters

arg2 [IN] COLORREF data

Returns

Newly set RRgb - RLPy.RRgb
color_red2 = RLPy.RRgb()
color_red2.FromCOLORREF(int(ff0000, 16))

FromXRGB ( self, arg2 )

Assign this color using hexadecimal format (0xrrggbb).

See Also: RLPy.RRgb.ToXRGB()

Parameters

arg2 [IN] RGB hexadecimal value - HEX

Returns

Newly set RRgb - RLPy.RRgb
color_red2 = RLPy.RRgb()
color_red2.FromXRGB(int(0000ff, 16))

G ( self, args )

Get the green value of this color (0-1).

See Also: RLPy.RRgb.Green()

Returns

Green value of this color - float (0-1)
color1 = RLPy.RRgb(0, 1, 0)
print(color1.G())               # 1

Green ( self )

Get the green value of this color (0-255).

See Also: RLPy.RRgb.G()

Returns

Green value of this color (0-255) - int
color1 = RLPy.RRgb(0, 1, 0)
print(color1.Green())           # 255

Normalize ( self )

Normalize RGB values so that their sum equals 1.

Returns

Normalized RRgb - RLPy.RRgb
color1 = RLPy.RRgb(1, 1, 0)
color1.Normalize()              # (0.5, 0.5, 0)

R ( self, args )

Get the red value of this color (0-1).

See Also: RLPy.RRgb.Red()

Returns

Red value of this color (0-1) - float
color1 = RLPy.RRgb(1, 0, 0)
print(color1.R())               # 1

Red ( self )

Get the red value of this color (0-255).

See Also: RLPy.RRgb.R()

Returns

Red value of this color (0-255) - int
color1 = RLPy.RRgb(1, 0, 0)
print(color1.Red())            # 255

Saturate ( self )

Clamp the RGB values to a range of 0 and 1. Values under 0 will become 0, and values over 1 will become 1.

Returns

This color saturated (RRgb) - RLPy.RRgb
color1 = RLPy.RRgb(1.2, -0.3, 0.5)
color1.Saturate()              # (1, 0, 0.5)

ToCOLORREF ( self )

Output COLORREF data from this color (0xbbggrr).

See Also: RLPy.RRgb.FromCOLORREF()

Returns

COLORREF data - int
color1 = RLPy.RRgb(0, 0, 1)
print(int(color1.ToCOLORREF()))          # 0xff0000

ToVector3f ( self )

Output 3D vector data from this color (RVector3f)

Returns

3D vector color data - RLPy.RVector3f
color1 = RLPy.RRgb(0, 0, 1)
print(color1.ToVector3f())

ToXRGB ( self )

Output hexadecimal data from this color (0xrrggbb)

See Also: RLPy.RRgb.FromXRGB()

Returns

Hexadecimal color data - int
color1 = RLPy.RRgb(0, 0, 1)
print(int(color1.ToXRGB()))              # 0xff