A colour is an object representing a combination of Red, Green, and Blue (RGB) intensity values, and is used to determine drawing colours.
See the entry for ColourDatabase for how a pointer to a predefined, named colour may be returned instead of creating a new colour.
Valid RGB values are in the range 0 to 255.
You can retrieve the current system colour settings with SystemSettings.
See also
__init__ | Default constructor. |
Alpha | Returns the alpha value, on platforms where alpha is not yet supported, this always returns ALPHA_OPAQUE. |
AlphaBlend | Blend colour, taking alpha into account. |
Blue | Returns the blue intensity. |
ChangeLightness | Colour wrapper for ChangeLightness(r,g,b,ialpha). |
Get | Get(includeAlpha=False) -> (r,g,b) or (r,g,b,a) |
GetAsString | Converts this colour to a String using the given flags. |
GetRGB | Gets the RGB or RGBA colour values as a single 32 bit value. |
GetRGBA | Gets the RGB or RGBA colour values as a single 32 bit value. |
Green | Returns the green intensity. |
IsOk | Returns True if the colour object is valid (the colour has been initialised with RGB values). |
MakeDisabled | Create a disabled (dimmed) colour from (in/out) rgb parameters. |
MakeGrey | Create a grey colour from (in/out) rgb parameters using integer arithmetic. |
MakeMono | Assign 0 or 255 to rgb out parameters. |
Red | Returns the red intensity. |
Set | Sets the RGB intensity values using the given values (first overload), extracting them from the packed long (second overload), using the given string (third overload). |
SetRGB | Sets the RGB or RGBA colour values from a single 32 bit value. |
SetRGBA | Sets the RGB or RGBA colour values from a single 32 bit value. |
__getitem__ | |
__len__ | |
__nonzero__ | |
__reduce__ | |
__repr__ | |
__setitem__ | |
__str__ | |
_copyFrom | For internal use only. |
__ne__ | Tests the inequality of two colours by comparing individual red, green, blue colours and alpha values. |
__eq__ | Tests the equality of two colours by comparing individual red, green, blue colours and alpha values. |
Pixel | See GetPixel |
RGB | See GetRGB and SetRGB |
RGBA | See GetRGBA and SetRGBA |
alpha | See Alpha |
blue | See Blue |
green | See Green |
red | See Red |
A colour is an object representing a combination of Red, Green, and Blue (RGB) intensity values, and is used to determine drawing colours.
Possible constructors:
Colour()
Colour(red, green, blue, alpha=ALPHA_OPAQUE)
Colour(colRGB)
Colour(colour)
Overloaded Implementations:
__init__ (self)
Default constructor.
__init__ (self, red, green, blue, alpha=ALPHA_OPAQUE)
Parameters: |
|
---|
__init__ (self, colRGB)
Parameters: | colRGB (long) – A packed RGB value. |
---|
__init__ (self, colour)
Copy constructor.
Parameters: | colour (Colour) – |
---|
Returns the alpha value, on platforms where alpha is not yet supported, this always returns ALPHA_OPAQUE.
Return type: | int |
---|
Blend colour, taking alpha into account.
Parameters: |
|
---|---|
Return type: | int |
New in version 2.9.0.
Returns the blue intensity.
Return type: | int |
---|
Overloaded Implementations:
ChangeLightness (self, ialpha)
Colour wrapper for ChangeLightness(r,g,b,ialpha).
Parameters: | ialpha (int) – |
---|---|
Return type: | Colour |
New in version 2.9.0.
ChangeLightness (r, g, b, ialpha)
ChangeLightness is a utility function that simply darkens or lightens a color, based on the specified percentage ialpha of 0 would be completely black, 200 completely white an ialpha of 100 returns the same colour.
Parameters: |
|
---|---|
Return type: | tuple |
Returns: | ( r, g, b ) |
New in version 2.9.0.
Get(includeAlpha=False) -> (r,g,b) or (r,g,b,a)
Returns the RGB intensity values as a tuple, optionally the alpha value as well.
Return type: | PyObject |
---|
Converts this colour to a String using the given flags.
The supported flags are C2S_NAME , to obtain the colour name (e.g. Colour(255,0,0) == “red”), C2S_CSS_SYNTAX , to obtain the colour in the “rgb(r,g,b)” or “rgba(r,g,b,a)” syntax (e.g. Colour(255,0,0,85) == “rgba(255,0,0,0.333)”), and C2S_HTML_SYNTAX , to obtain the colour as “#” followed by 6 hexadecimal digits (e.g. Colour(255,0,0) == “#``FF0000``”).
This function never fails and always returns a non-empty string but asserts if the colour has alpha channel (i.e. is non opaque) but C2S_CSS_SYNTAX (which is the only one supporting alpha) is not specified in flags.
Parameters: | flags (long) – |
---|---|
Return type: | string |
New in version 2.7.0.
Gets the RGB or RGBA colour values as a single 32 bit value.
The returned value is of the same form as expected by SetRGB and SetRGBA .
Notice that GetRGB returns the value with 0 as its highest byte independently of the value actually returned by Alpha . So for a fully opaque colour, the return value of GetRGBA is 0xFFBBGGRR while that of GetRGB is 0x00BBGGRR .
Return type: | int |
---|
New in version 2.9.1.
Gets the RGB or RGBA colour values as a single 32 bit value.
The returned value is of the same form as expected by SetRGB and SetRGBA .
Notice that GetRGB returns the value with 0 as its highest byte independently of the value actually returned by Alpha . So for a fully opaque colour, the return value of GetRGBA is 0xFFBBGGRR while that of GetRGB is 0x00BBGGRR .
Return type: | int |
---|
New in version 2.9.1.
Returns the green intensity.
Return type: | int |
---|
Returns True if the colour object is valid (the colour has been initialised with RGB values).
Return type: | bool |
---|
Create a disabled (dimmed) colour from (in/out) rgb parameters.
Parameters: |
|
---|---|
Return type: | tuple |
Returns: | ( r, g, b ) |
New in version 2.9.0.
Overloaded Implementations:
MakeGrey (r, g, b)
Create a grey colour from (in/out) rgb parameters using integer arithmetic.
Parameters: |
|
---|---|
Return type: | tuple |
Returns: | ( r, g, b ) |
New in version 2.9.0.
MakeGrey (r, g, b, weight_r, weight_g, weight_b)
Create a grey colour from (in/out) rgb parameters using floating point arithmetic.
Defaults to using the standard ITU-T BT.601 when converting to YUV, where every pixel equals (R weight_r) + (G weight_g) + (B weight_b).
Parameters: |
|
---|---|
Return type: | tuple |
Returns: | ( r, g, b ) |
New in version 2.9.0.
Assign 0 or 255 to rgb out parameters.
Parameters: | on (bool) – |
---|---|
Return type: | tuple |
Returns: | ( r, g, b ) |
New in version 2.9.0.
Returns the red intensity.
Return type: | int |
---|
Sets the RGB intensity values using the given values (first overload), extracting them from the packed long (second overload), using the given string (third overload).
When using third form, Set accepts: colour names (those listed in ColourDatabase), the CSS-like "rgb(r,g,b)" or "rgba(r,g,b,a)" syntax (case insensitive) and the HTML-like syntax: "#" followed by 6 hexadecimal digits for red, green, blue components.
Returns True if the conversion was successful, False otherwise.
New in version 2.7.0.
Overloaded Implementations:
Set (self, red, green, blue, alpha=ALPHA_OPAQUE)
Parameters: |
|
---|
Set (self, RGB)
Parameters: | RGB (long) – |
---|
Set (self, str)
Parameters: | str (string) – |
---|---|
Return type: | bool |
Sets the RGB or RGBA colour values from a single 32 bit value.
The arguments colRGB and colRGBA should be of the form 0x00BBGGRR and 0xAABBGGRR respectively where 0xRR , 0xGG , 0xBB and 0xAA are the values of the red, blue, green and alpha components.
Notice the right-to-left order of components!
Parameters: | colRGB (int) – |
---|
New in version 2.9.1.
Sets the RGB or RGBA colour values from a single 32 bit value.
The arguments colRGB and colRGBA should be of the form 0x00BBGGRR and 0xAABBGGRR respectively where 0xRR , 0xGG , 0xBB and 0xAA are the values of the red, blue, green and alpha components.
Notice the right-to-left order of components!
Parameters: | colRGBA (int) – |
---|
New in version 2.9.1.
For internal use only.
Tests the inequality of two colours by comparing individual red, green, blue colours and alpha values.
Parameters: | colour (Colour) – |
---|
Tests the equality of two colours by comparing individual red, green, blue colours and alpha values.
Parameters: | colour (Colour) – |
---|
See GetPixel