These functions exist for easy creation of Color objects from different input formats.
Create Color from string.
Parameters: |
|
---|---|
Return type: | Color or factory instance |
Creates new instance from a valid color specification string as in CSS 2.1. Supported formats include rgb, rgba, hsl, hsla, color identifiers, hexadecimal values, integer and percent values where applicable. When factory is specified this type is used instead of default Color type.
>>> from_string('red')
<Color(r=1,g=0,b=0,a=1) object at 0x10320e400L>
>>> from_string('rgb(1,1,0)')
<Color(r=1,g=1,b=0,a=1) object at 0x103270600L>
>>> from_string('#fff')
<Color(r=1,g=1,b=1,a=1) object at 0x103251800L>
>>> from_string('hsla(50%, 100%, 100%, 0.5)')
<Color(r=0,g=1,b=1,a=0.5) object at 0x103252a00L>
Create opaque Color from red, green and blue components.
Parameters: |
|
---|---|
Return type: | Color or factory instance |
Red, green and blue components should be numbers between 0 and 1 inclusive. Resulting color is opaque (alpha channel equal to 1). When factory is specified this type is used instead of default Color type.
>>> from_rgb(0.5, 1, 0.5)
<Color(r=0.5,g=1,b=0.5,a=1) object at 0x103266200L>
Create Color from red, green, blue and alpha components.
Parameters: |
|
---|---|
Return type: | Color or factory instance |
Red, green, blue and alpha components should be numbers between 0 and 1 inclusive.
>>> from_rgba(1, 1, 0, 0.5)
<Color(r=1,g=1,b=0,a=0.5) object at 0x103222600L>
Object representing color information.
Set or get alpha channel information.
The value ought to be a float between 0 and 1.
Return type: | float or int |
---|
Set or get blue channel information.
The value ought to be a float between 0 and 1.
Return type: | float or int |
---|
Return hue, saturation and lightness components.
Return type: | tuple |
---|
Return RGB triplet as single 24 bit integer.
Returns an integer representing this color. Highest 8 bit represent red channel information.
Return red, green and blue components.
Return type: | tuple |
---|
Returns tuple containing red, green and blue channel information as numbers between 0 and 1.
Return red, gren and blue components as 8bit integers
Return type: | tuple |
---|
Returns tuple containing red, green and blue in this order as 8bit integers randing from 0 to 255
Return red, green, blue and alpha components.
Return type: | tuple |
---|
Returns tuple containing red, green, blue and alpha channel information as numbers between 0 and 1.
Return string representation of color.
Return type: | str |
---|
Returns standard CSS string representation of color either rgb(r, g, b) or rgba(r, g, b, a) when color is not fully opaque.
Set or get green channel information.
The value ought to be a float between 0 and 1.
Return type: | float or int |
---|
Check if color is fully opaque.
Return type: | bool |
---|
Returns True if alpha component is exactly equal to 1, otherwise False.
>>> from_string('red').opaque
True
>>> from_string('transparent').opaque
False
Set or get red channel information.
The value ought to be a float between 0 and 1.
Return type: | float or int |
---|
Set red, green and blue components all at once.
Parameters: |
|
---|
Components should be numbers between 0 and 1. Alpha component remains unchanged.
Set red, green, blue and alpha components all at once.
Parameters: |
|
---|
Components should be numbers between 0 and 1.
Resets color value of this instance from string.
Usage and parameters identical to factory function from_string().
Check if color is fully transparent.
Return type: | bool |
---|
Returns True if alpha component is exactly equal to 0, otherwise False.
>>> from_string('blue').transparent
False
>>> from_string('transparent').transparent
True