This documentation is for an unreleased version of MPF!
This is the developer documentation for MPF 0.51, which is the “dev” (next) release of MPF that is a work-in-progress. Use the “Read the Docs” link in the lower left corner to view the developer docs for the version of MPF you’re using.
RGBColor(color: Union[RGBColor, str, List[int], Tuple[int, int, int]] = None)¶
One RGB Color.
Methods & Attributes
The RGBColor has the following methods & attributes available. Note that methods & attributes inherited from the base class are not included here.
add_color(name: str, color: Union[RGBColor, str, List[int], Tuple[int, int, int]])¶
Add (or updates if it already exists) a color.
Note that this is not permanent, the list is reset when MPF restarts (though you can define your own custom colors in your config file’s colors: section). You can use this function to dynamically change the values of colors in shows (they take place the next time an LED switches to that color).
- name – String name of the color you want to add/update
- color – The color you want to set. You can pass the same types as the RGBColor class constructor, including a tuple or list of RGB ints (0-255 each), a hex string, an RGBColor instance, or a dictionart of red, green, blue key/value pairs.
blend(start_color, end_color, fraction)¶
Blend two colors.
- start_color – The start color
- end_color – The end color
- fraction – The fraction between 0 and 1 that is used to set the blend point between the two colors.
- Returns: An RGBColor object that is a blend between the start and end
Return the blue component of the RGB color representation.
Return the green component of the RGB color representation.
Return a 6-char HEX representation of the color.
hex_to_rgb(_hex: str, default=None) → Tuple[int, int, int]¶
Convert a HEX color representation to an RGB color representation.
- _hex – The 3- or 6-char hexadecimal string representing the color value.
- default – The default value to return if _hex is invalid.
- Returns: RGB representation of the input HEX value as a 3-item tuple
- with each item being an integer 0-255.
Return the color name or None.
Returns a string containing a standard color name or None if the current RGB color does not have a standard name.
name_to_rgb(name: str, default=(0, 0, 0)) → Tuple[int, int, int]¶
Convert a standard color name to an RGB value (tuple).
If the name is not found, the default value is returned. :param name: A standard color name. :param default: The default value to return if the color name is not found. :return: RGB representation of the named color. :rtype: tuple
random_rgb() → Tuple[int, int, int]¶
Generate a uniformly random RGB value.
Returns: A tuple of three integers with values between 0 and 255 inclusive
Return the red component of the RGB color representation.
Return an RGB representation of the color.
rgb_to_hex(rgb: Tuple[int, int, int]) → str¶
Convert an RGB color representation to a HEX color representation.
- (r, g, b) :: r -> [0, 255]
- g -> [0, 255] b -> [0, 255]
Parameters: rgb – A tuple of three numeric values corresponding to the red, green, and blue value. Returns: HEX representation of the input RGB value. Return type: str
string_to_rgb(value: str, default=(0, 0, 0)) → Tuple[int, int, int]¶
Convert a string which could be either a standard color name or a hex value to an RGB value (tuple).
If the name is not found and the supplied value is not a valid hex string it raises an error. :param value: A standard color name or hex value. :param default: The default value to return if the color name is not found and the supplied value is not a valid hex color string. :return: RGB representation of the named color. :rtype: tuple