Difference between revisions of "IC Python API:RLPy RRgb"
Chuck (RL) (Talk | contribs) m |
Chuck (RL) (Talk | contribs) m |
||
(3 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
== Description == | == Description == | ||
− | Primary color class that stores data for red (R), green (G), and blue (B). The value stored in RRgb ranges from 0 | + | Primary color class that stores data for red (R), green (G), and blue (B). The value stored in [[IC_Python_API:RLPy_RRgb|RRgb]] ranges from 0-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: |
{|class="wikitable" | {|class="wikitable" | ||
Line 36: | Line 36: | ||
|} | |} | ||
− | RRgb does not include alpha data. | + | [[IC_Python_API:RLPy_RRgb|RRgb]] does not include alpha data. Use [[IC_Python_API:RLPy_RColor|RColor]] instead if alpha channel is needed. This class also provides ways to convert to other color formats: |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
# create color | # create color | ||
color_red1 = RLPy.RRgb(1, 0, 0) | color_red1 = RLPy.RRgb(1, 0, 0) | ||
Line 54: | Line 54: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | See Also: [ | + | See Also: [[IC_Python_API:RLPy_RColor|RColor]] |
== Member Functions == | == Member Functions == | ||
Line 60: | Line 60: | ||
=== B ( self, args ) === | === B ( self, args ) === | ||
− | Get the blue value of this color (0 | + | Get the blue value of this color (0-1). |
− | See Also: [[# | + | See Also: [[#Blue ( self )|Blue]] |
==== Returns ==== | ==== Returns ==== | ||
− | :Value for the blue channel (0 | + | :Value for the blue channel (0-1) - float |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
color1 = RLPy.RRgb(0, 0, 1) | color1 = RLPy.RRgb(0, 0, 1) | ||
print(color1.B()) # 1 | print(color1.B()) # 1 | ||
Line 74: | Line 74: | ||
=== Blue ( self ) === | === Blue ( self ) === | ||
− | Get the blue value of this color (0 | + | Get the blue value of this color (0-255). |
− | See Also: [[# | + | See Also: [[#B ( self, args )|B]] |
==== Returns ==== | ==== Returns ==== | ||
:Value for the blue channel (0-255) - int | :Value for the blue channel (0-255) - int | ||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
color1 = RLPy.RRgb(0, 0, 1) | color1 = RLPy.RRgb(0, 0, 1) | ||
print(color1.Blue()) # 255 | print(color1.Blue()) # 255 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | === From ( self, | + | === From ( self, [[#R ( self, args )|R]], [[#G ( self, args )|G]], b ) === |
− | + | Adjust color using 32 bit (0-255). | |
==== Parameters ==== | ==== Parameters ==== | ||
Line 96: | Line 96: | ||
==== Returns ==== | ==== Returns ==== | ||
− | : | + | :(0-255) color - [[IC_Python_API:RLPy_RRgb|RRgb]] |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
− | color1 = | + | color1 = [[IC_Python_API:RLPy_RRgb|RRgb]] |
color1.From(255, 0, 0) | color1.From(255, 0, 0) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 105: | Line 105: | ||
=== FromCOLORREF ( self, arg2 ) === | === FromCOLORREF ( self, arg2 ) === | ||
− | + | Adjust color using COLORREF (0xbbggrr). | |
− | See Also: [[# | + | See Also: [[#ToCOLORREF ( self )|ToCOLORREF]] |
==== Parameters ==== | ==== Parameters ==== | ||
Line 113: | Line 113: | ||
==== Returns ==== | ==== Returns ==== | ||
− | : | + | :Changed color - [[IC_Python_API:RLPy_RRgb|RRgb]] |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
− | color_red2 = | + | color_red2 = [[IC_Python_API:RLPy_RRgb|RRgb]] |
color_red2.FromCOLORREF(int(‘ff0000’, 16)) | color_red2.FromCOLORREF(int(‘ff0000’, 16)) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 122: | Line 122: | ||
=== FromXRGB ( self, arg2 ) === | === FromXRGB ( self, arg2 ) === | ||
− | Assign this color using hexadecimal | + | Assign this color using hexadecimal (0xrrggbb). |
− | See Also: [[# | + | See Also: [[#ToXRGB ( self )|ToXRGB]] |
==== Parameters ==== | ==== Parameters ==== | ||
Line 130: | Line 130: | ||
==== Returns ==== | ==== Returns ==== | ||
− | : | + | :Changed color - [[IC_Python_API:RLPy_RRgb|RRgb]] |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
− | color_red2 = | + | color_red2 = [[IC_Python_API:RLPy_RRgb|RRgb]] |
color_red2.FromXRGB(int(‘0000ff’, 16)) | color_red2.FromXRGB(int(‘0000ff’, 16)) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 141: | Line 141: | ||
Get the green value of this color (0-1). | Get the green value of this color (0-1). | ||
− | See Also: [[# | + | See Also: [[#Green ( self )|Green]] |
==== Returns ==== | ==== Returns ==== | ||
− | :Green value of this color | + | :Green value of this color (0-1) - float |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
color1 = RLPy.RRgb(0, 1, 0) | color1 = RLPy.RRgb(0, 1, 0) | ||
print(color1.G()) # 1 | print(color1.G()) # 1 | ||
Line 155: | Line 155: | ||
Get the green value of this color (0-255). | Get the green value of this color (0-255). | ||
− | See Also: [[# | + | See Also: [[#G ( self, args )|G]] |
==== Returns ==== | ==== Returns ==== | ||
:Green value of this color (0-255) - int | :Green value of this color (0-255) - int | ||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
color1 = RLPy.RRgb(0, 1, 0) | color1 = RLPy.RRgb(0, 1, 0) | ||
print(color1.Green()) # 255 | print(color1.Green()) # 255 | ||
Line 170: | Line 170: | ||
==== Returns ==== | ==== Returns ==== | ||
− | :Normalized | + | :Normalized color - [[IC_Python_API:RLPy_RRgb|RRgb]] |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
color1 = RLPy.RRgb(1, 1, 0) | color1 = RLPy.RRgb(1, 1, 0) | ||
color1.Normalize() # (0.5, 0.5, 0) | color1.Normalize() # (0.5, 0.5, 0) | ||
Line 181: | Line 181: | ||
Get the red value of this color (0-1). | Get the red value of this color (0-1). | ||
− | See Also: [[# | + | See Also: [[#Red ( self )|Red]] |
==== Returns ==== | ==== Returns ==== | ||
:Red value of this color (0-1) - float | :Red value of this color (0-1) - float | ||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
color1 = RLPy.RRgb(1, 0, 0) | color1 = RLPy.RRgb(1, 0, 0) | ||
print(color1.R()) # 1 | print(color1.R()) # 1 | ||
Line 195: | Line 195: | ||
Get the red value of this color (0-255). | Get the red value of this color (0-255). | ||
− | See Also: [[# | + | See Also: [[#R ( self, args )|R]] |
==== Returns ==== | ==== Returns ==== | ||
:Red value of this color (0-255) - int | :Red value of this color (0-255) - int | ||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
color1 = RLPy.RRgb(1, 0, 0) | color1 = RLPy.RRgb(1, 0, 0) | ||
print(color1.Red()) # 255 | print(color1.Red()) # 255 | ||
Line 210: | Line 210: | ||
==== Returns ==== | ==== Returns ==== | ||
− | :This color saturated (RRgb) - | + | :This color saturated (RRgb) - [[IC_Python_API:RLPy_RRgb|RRgb]] |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
color1 = RLPy.RRgb(1.2, -0.3, 0.5) | color1 = RLPy.RRgb(1.2, -0.3, 0.5) | ||
color1.Saturate() # (1, 0, 0.5) | color1.Saturate() # (1, 0, 0.5) | ||
Line 219: | Line 219: | ||
=== ToCOLORREF ( self ) === | === ToCOLORREF ( self ) === | ||
− | Output COLORREF data from this color (0xbbggrr). | + | Output COLORREF data from this color (0xbbggrr). |
− | See Also: [[# | + | See Also: [[#FromCOLORREF ( self, arg2 )|FromCOLORREF]] |
==== Returns ==== | ==== Returns ==== | ||
− | :COLORREF data - int | + | :COLORREF color data - int |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
color1 = RLPy.RRgb(0, 0, 1) | color1 = RLPy.RRgb(0, 0, 1) | ||
print(int(color1.ToCOLORREF())) # 0xff0000 | print(int(color1.ToCOLORREF())) # 0xff0000 | ||
Line 233: | Line 233: | ||
=== ToVector3f ( self ) === | === ToVector3f ( self ) === | ||
− | Output 3D vector data from this color | + | Output 3D vector data from this color. |
==== Returns ==== | ==== Returns ==== | ||
− | :3D vector color data - | + | :3D vector color data - [[IC_Python_API:RLPy_RVector3|RVector3]] |
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
color1 = RLPy.RRgb(0, 0, 1) | color1 = RLPy.RRgb(0, 0, 1) | ||
print(color1.ToVector3f()) | print(color1.ToVector3f()) | ||
Line 247: | Line 247: | ||
Output hexadecimal data from this color (0xrrggbb) | Output hexadecimal data from this color (0xrrggbb) | ||
− | See Also: [[ | + | See Also: [[#FromXRGB ( self, arg2 )|FromXRGB]] |
==== Returns ==== | ==== Returns ==== | ||
:Hexadecimal color data - int | :Hexadecimal color data - int | ||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="python" line='line'> |
color1 = RLPy.RRgb(0, 0, 1) | color1 = RLPy.RRgb(0, 0, 1) | ||
print(int(color1.ToXRGB())) # 0xff | print(int(color1.ToXRGB())) # 0xff | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 19:39, 13 April 2020
Contents
- 1 Description
- 2 Member Functions
- 2.1 B ( self, args )
- 2.2 Blue ( self )
- 2.3 From ( self, R, G, b )
- 2.4 FromCOLORREF ( self, arg2 )
- 2.5 FromXRGB ( self, arg2 )
- 2.6 G ( self, args )
- 2.7 Green ( self )
- 2.8 Normalize ( self )
- 2.9 R ( self, args )
- 2.10 Red ( self )
- 2.11 Saturate ( self )
- 2.12 ToCOLORREF ( self )
- 2.13 ToVector3f ( self )
- 2.14 ToXRGB ( self )
- Main article: Modules.
- Last modified: 04/13/2020
Description
Primary color class that stores data for red (R), green (G), and blue (B). The value stored in RRgb ranges from 0-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 is 0 to 1, and the range of values retrieved by 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 RColor instead if alpha channel is needed. This class also provides ways to convert to other color formats:
1 # create color
2 color_red1 = RLPy.RRgb(1, 0, 0)
3 color_red2 = RLPy.RRgb()
4 color_red2.From(255, 0, 0)
5 color_red3 = RLPy.RRgb.RED
6
7 # print color
8 print( color_red1.R() ) # 1
9 print( color_red1.Red() ) # 255
10
11 # convert different format
12 print(hex(color1.ToXRGB())) # 0xff0000
13 print(hex(color1.ToCOLORREF())) # 0xff
See Also: RColor
Member Functions
B ( self, args )
Get the blue value of this color (0-1).
See Also: Blue
Returns
- Value for the blue channel (0-1) - float
1 color1 = RLPy.RRgb(0, 0, 1)
2 print(color1.B()) # 1
Blue ( self )
Get the blue value of this color (0-255).
See Also: B
Returns
- Value for the blue channel (0-255) - int
1 color1 = RLPy.RRgb(0, 0, 1)
2 print(color1.Blue()) # 255
From ( self, R, G, b )
Adjust color using 32 bit (0-255).
Parameters
- r [IN] Red value (0-255) - int
- g [IN] Green value (0-255) - int
- b [IN] Blue value (0-255) - int
Returns
- (0-255) color - RRgb
1 color1 = [[IC_Python_API:RLPy_RRgb|RRgb]]
2 color1.From(255, 0, 0)
FromCOLORREF ( self, arg2 )
Adjust color using COLORREF (0xbbggrr).
See Also: ToCOLORREF
Parameters
- arg2 [IN] COLORREF data
Returns
- Changed color - RRgb
1 color_red2 = [[IC_Python_API:RLPy_RRgb|RRgb]]
2 color_red2.FromCOLORREF(int(‘ff0000’, 16))
FromXRGB ( self, arg2 )
Assign this color using hexadecimal (0xrrggbb).
See Also: ToXRGB
Parameters
- arg2 [IN] RGB hexadecimal value - HEX
Returns
- Changed color - RRgb
1 color_red2 = [[IC_Python_API:RLPy_RRgb|RRgb]]
2 color_red2.FromXRGB(int(‘0000ff’, 16))
G ( self, args )
Get the green value of this color (0-1).
See Also: Green
Returns
- Green value of this color (0-1) - float
1 color1 = RLPy.RRgb(0, 1, 0)
2 print(color1.G()) # 1
Green ( self )
Get the green value of this color (0-255).
See Also: G
Returns
- Green value of this color (0-255) - int
1 color1 = RLPy.RRgb(0, 1, 0)
2 print(color1.Green()) # 255
Normalize ( self )
Normalize RGB values so that their sum equals 1.
Returns
- Normalized color - RRgb
1 color1 = RLPy.RRgb(1, 1, 0)
2 color1.Normalize() # (0.5, 0.5, 0)
R ( self, args )
Get the red value of this color (0-1).
See Also: Red
Returns
- Red value of this color (0-1) - float
1 color1 = RLPy.RRgb(1, 0, 0)
2 print(color1.R()) # 1
Red ( self )
Get the red value of this color (0-255).
See Also: R
Returns
- Red value of this color (0-255) - int
1 color1 = RLPy.RRgb(1, 0, 0)
2 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) - RRgb
1 color1 = RLPy.RRgb(1.2, -0.3, 0.5)
2 color1.Saturate() # (1, 0, 0.5)
ToCOLORREF ( self )
Output COLORREF data from this color (0xbbggrr).
See Also: FromCOLORREF
Returns
- COLORREF color data - int
1 color1 = RLPy.RRgb(0, 0, 1)
2 print(int(color1.ToCOLORREF())) # 0xff0000
ToVector3f ( self )
Output 3D vector data from this color.
Returns
- 3D vector color data - RVector3
1 color1 = RLPy.RRgb(0, 0, 1)
2 print(color1.ToVector3f())
ToXRGB ( self )
Output hexadecimal data from this color (0xrrggbb)
See Also: FromXRGB
Returns
- Hexadecimal color data - int
1 color1 = RLPy.RRgb(0, 0, 1)
2 print(int(color1.ToXRGB())) # 0xff