topologicpy.Color module
- class topologicpy.Color.Color
Bases:
objectMethods
AddHex()Adds the input hexadecimal color codes channel-wise, clipping each channel to a max of 255.
AnyToHex(color)Converts a color to a hexadecimal color string.
Average(*colors[, silent])Averages the input list of hex colors.
ByCSSNamedColor(color[, alpha])Creates a Color from a CSS named color string.
ByHEX(hex[, alpha])Converts a hexadecimal color string to RGB color values.
ByValueInRange([value, minValue, maxValue, ...])Returns the r, g, b, (and optionally) a list of numbers representing the red, green, blue and alpha color elements.
CMYKToHex(cmyk)Convert a CMYK color (list of 4 values) to its hexadecimal representation.
CSSNamedColor(color)Returns the CSS Named color that most closely matches the input color.
Returns a list of all CSS named colors.
PlotlyColor(color[, alpha, useAlpha])Returns a plotly color string based on the input list of [r, g, b] or [r, g, b, a].
RGBToHex(rgb)Converts RGB color values to a hexadecimal color string.
- AddHex()
Adds the input hexadecimal color codes channel-wise, clipping each channel to a max of 255.
- Parameters
- colors*list or str
The input list of hexadecimal colors.
- Returns
- str
The resulting hex color after addition (e.g., ‘#FF88FF’).
- static AnyToHex(color)
Converts a color to a hexadecimal color string.
- Parameters
- colorlist or str
The input color parameter which can be any of RGB, CMYK, CSS Named Color, or Hex
- Returns
- str
A hexadecimal color string in the format ‘#RRGGBB’.
- static Average(*colors, silent: bool = False)
Averages the input list of hex colors.
- Parameters
- colors*list or str
The input color parameter which can be any of RGB, CMYK, CSS Named Color, or Hex
- Returns
- str
A hexadecimal color string in the format ‘#RRGGBB’.
- static ByCSSNamedColor(color, alpha: float = None)
Creates a Color from a CSS named color string. See https://developer.mozilla.org/en-US/docs/Web/CSS/named-color
- Parameters
- colorstr
A CSS named color.
- alphafloat , optional
THe desired alpha (transparency value). Default is None which means no alpha value will be included in the returned list.
- Returns
- list
The color expressed as an [r, g, b] or an [r, g, b, a] list.
- static ByHEX(hex: str, alpha: float = None)
Converts a hexadecimal color string to RGB color values.
- Parameters
- hexstr
A hexadecimal color string in the format ‘#RRGGBB’.
- alphafloat , optional
The transparency value. 0.0 means the color is fully transparent, 1.0 means the color is fully opaque. Default is None which means no transparency value will be included in the returned color.
- Returns
- list
The color expressed as an [r, g, b] or an [r, g, b, a] list.
- static ByValueInRange(value: float = 0.5, minValue: float = 0.0, maxValue: float = 1.0, alpha: float = None, colorScale='viridis')
Returns the r, g, b, (and optionally) a list of numbers representing the red, green, blue and alpha color elements.
- Parameters
- valuefloat , optional
The input value. Default is 0.5.
- minValuefloat , optional
the input minimum value. Default is 0.0.
- maxValuefloat , optional
The input maximum value. Default is 1.0.
- alphafloat , optional
The alpha (transparency) value. 0.0 means the color is fully transparent, 1.0 means the color is fully opaque. Default is 1.0.
- useAlphabool , optional
If set to True, the returns list includes the alpha value as a fourth element in the list.
- colorScalestr , optional
The desired type of plotly color scales to use (e.g. ‘Viridis’, ‘Plasma’). Default is ‘Viridis’. For a full list of names, see https://plotly.com/python/builtin-colorscales/.
- Returns
- list
The color expressed as an [r, g, b] or an [r, g, b, a] list.
- static CMYKToHex(cmyk)
Convert a CMYK color (list of 4 values) to its hexadecimal representation.
- Parameters
- colorlist
cmyk (list or tuple): CMYK color values as [C, M, Y, K], each in the range 0 to 1.
- Returns
- str: The hexadecimal color string for Plotly (e.g., ‘#FFFFFF’).
- static CSSNamedColor(color)
Returns the CSS Named color that most closely matches the input color. The input color is assumed to be in the format [r, g, b]. See https://developer.mozilla.org/en-US/docs/Web/CSS/named-color
- Parameters
- colorlist
The input color. This is assumed to be in the format [r, g, b]
- Returns
- str
The CSS named color that most closely matches the input color.
- static CSSNamedColors()
Returns a list of all CSS named colors. See https://developer.mozilla.org/en-US/docs/Web/CSS/named-color
- Parameters
- Returns
- list
The list of all CSS named colors.
- static PlotlyColor(color, alpha=1.0, useAlpha=False)
Returns a plotly color string based on the input list of [r, g, b] or [r, g, b, a]. If your list is [r, g, b], you can optionally specify an alpha value
- Parameters
- colorlist
The input color list. This is assumed to be in the format [r, g, b] or [r, g, b, a] where the range is from 0 to 255.
- alphafloat , optional
The transparency value. 0.0 means the color is fully transparent, 1.0 means the color is fully opaque. Default is 1.0.
- useAlphabool , optional
If set to True, the returns list includes the alpha value as a fourth element in the list.
- Returns
- str
The plotly color string.
- static RGBToHex(rgb)
Converts RGB color values to a hexadecimal color string.
- Parameters
- rgbtuple
A tuple containing three integers representing the RGB values.
- Returns
- str
A hexadecimal color string in the format ‘#RRGGBB’.