gewel.color.Color
- class gewel.color.Color(red: Union[float, Tvf, PyTvf], green: Union[float, Tvf, PyTvf], blue: Union[float, Tvf, PyTvf], alpha: Optional[Union[float, Tvf, PyTvf]] = None)[source]
Bases:
gewel.color.BaseColorA color with three components red, green, and blue representing the relative level or red, green, and blue respectively, and alpha fourth component alpha (alpha) representing opacity. All should be in the range [0.0, 1.0]. Note that these do not need to be fixed floating point values. They can also be time varying floats of type ~tvx.Tvf.
An alpha value of 1.0 indicates opaque and 0.0 indicates transparent. Values in between are semi-transparent.
- Parameters
red (Union[float, Tvf, PyTvf]) – Red color component.
green (Union[float, Tvf, PyTvf]) – Blue color component.
blue (Union[float, Tvf, PyTvf]) – Green color component.
alpha (Union[float, Tvf, PyTvf]) – Opacity. 0.0 means transparent. 1.0 means opaque. Values in between indicate partial transparency.
Methods
Construct color from a hexadecimal string.
from_tupleIndicates whether the color is transparent or not, i.e. whether its alpha is certain to be zero.
Construct a (red, green, blue, alpha) tuple representing the color.
with_alphaAttributes
Red color component.
Green color component.
Blue color component.
Opacity.
- alpha: Union[float, Tvf, PyTvf]
Opacity. 0.0 means transparent. 1.0 means opaque. Values in between indicate partial transparency.
- blue: Union[float, Tvf, PyTvf]
Blue color component.
- classmethod from_string(hex_str: str) gewel.color.Color[source]
Construct color from a hexadecimal string.
The string should be of the form
"#RRGGBB"or"#RRGGBBAA"where the charactersRRare two hexadecimal digits representing the level of red in the color,BBis for blue,GGis for green, andAAis for the alpha component. Note that ifAAis not present the color will be fully opaque (equivalent to an alpha of"FF"in hex.For example:
red = Color.from_string('#FF0000') # implied alpha red_a = Color.from_string('#FF0000FF') # explicit alpha semi_transparent_red = Color.from_string('#FF00007F')
produces three color objects. The first two are the exact same opaque red color. The third is also red, but it is semi-transparent, so when it is drawn, objects drawn under it will partially show through.
There are many different color tables and pickers available to help you choose the hex strings for colors you might wish to use. The Wikipedia page on web colors https://en.wikipedia.org/wiki/Web_colors is a good place to start.
- Parameters
hex_str – The hex string to parse out into a color.
- Returns
A newly constructed object representing the color specified by the hex string.
- Return type
- Raises
ValueError – if the string is not a proper hex string of the form
"#RRGGBB"or"#RRGGBBAA".
- green: Union[float, Tvf, PyTvf]
Green color component.
- is_transparent() bool[source]
Indicates whether the color is transparent or not, i.e. whether its alpha is certain to be zero. Checking this may be useful in checking whether something needs to be rendered or not. If the color it would be rendered is transparent then it does not.
- Returns
True if the color is transparent. False otherwise.
- Return type
bool
- red: Union[float, Tvf, PyTvf]
Red color component.
- tuple(t: float, alpha_multiplier: Union[float, Tvf, PyTvf] = 1.0) Tuple[float, float, float, float][source]
Construct a (red, green, blue, alpha) tuple representing the color. The red, green, and blue components are determined by the color. The alpha component may be affected by the value of the alpha_multiplier parameter.
- Parameters
t – The time for which we want the tuple.
alpha_multiplier – A multiplicative factor for the alpha. The value should be between 0.0 and 1.0. It will be multiplied by the alpha of the color to produce the fourth element of the resulting tuple. Passing in 0.0 will produce alpha transparent result (alpha = 0.0) while passing in the default value of 1.0 will leave the alpha of the color unchanged.
- Returns
A four element tuple, (red, green, blue, alpha) of color components for red, green, blue, and alpha (opacity). All are in the range [0.0, 1.0].
- Return type
tuple