pyrocko.color

Color utilities and built-in color palettes for a consistent look.

Color formats

RGB, RGBA

Integer values for red, green blue, alpha, in the range [0, 255].:

Color('RGBA(255, 255, 255, 255)')  # from string
Color('RGB(255, 255, 255)')
Color(255, 255, 255, 255)          # from values
Color(255, 255, 255)

rgb, rgba

Floating point values in the range [0.0, 1.0].:

Color('rgba(1, 1, 1, 1)')   # from string
Color('rgb(1, 1, 1)')
Color(1.0, 1.0, 1.0, 1.0)   # from values
Color(1.0, 1.0, 1.0)

hex

Hexadecimal value with 3, 4, 6 or 8 digits.:

Color('#fff')
Color('#ffff')
Color('#ffffff')
Color('#ffffffff')

name

See g_named_colors for a complete list of available colors.:

Color('white')
Color('butter1')
Color('skyblue2')
g_named_colors

Dict mapping color names to Color objects.

Functions

parse_color(s)

Translate color string into rgba tuple.

simplify_hex(s)

Simplifiy a hex color code if possible

to_float_1(i)

Convert integer to floating point color component

to_int_255(f)

Convert floating point to integer color component

Classes

Color(*args, **kwargs)

Color with red, green, blue and alpha values.

ColorGroup(**kwargs)

Group of predefined colors.

Component(...)

Undocumented.

Exceptions

ColorError

Raised for invalid color specifications and conversions.

InvalidColorString(s)

Raised for invalid color string definitions.

exception ColorError[source]

Bases: ValueError

Raised for invalid color specifications and conversions.

exception InvalidColorString(s)[source]

Bases: ColorError

Raised for invalid color string definitions.

parse_color(s)[source]

Translate color string into rgba tuple.

Parameters:

s (str) – Color definition.

Returns:

Color value in rgba form.

Return type:

tuple of 4 float

to_int_255(f)[source]

Convert floating point to integer color component

Convert a floating point color component (range [0.0, 1.0]) to an integer color component (range [0, 255])

Parameters:

f (float) – rgba floating point color component

Returns:

RGBA integer color component

Return type:

int

to_float_1(i)[source]

Convert integer to floating point color component

Convert an integer color component (range [0, 255]) to a floating point color component (range [0.0, 1.0])

Parameters:

i (int) – RGBA integer color component

Returns:

rgba floating point color component

Return type:

float

simplify_hex(s)[source]

Simplifiy a hex color code if possible

E.g.:
  • #ffffffff -> #fff

  • #11aabbff -> #1ab

Parameters:

s (str) – hex color string

Returns:

simplified hex color string

Return type:

str

class Component(...) float[source]

Bases: Float

Undocumented.

class Color(*args, **kwargs)[source]

Bases: SObject

Color with red, green, blue and alpha values.

The color can be specified as a color string or by giving the component values in int or float format.

Examples:

Color('black')
Color('RGBA(255, 255, 255, 255)')
Color('RGB(255, 255, 255)')
Color('rgba(1.0, 1.0, 1.0, 1.0')')
Color('rgb(1.0, 1.0, 1.0')')
Color(255, 255, 255, 255)
Color(255, 255, 255)
Color(1.0, 1.0, 1.0, 1.0)
Color(1.0, 1.0, 1.0)
Color(r=1.0, g=1.0, b=1.0, a=1.0)

The internal representation is rgba.

name

str, optional

r

float (Component), default: 0.0

Red component [0., 1.].

g

float (Component), default: 0.0

Green component [0., 1.].

b

float (Component), default: 0.0

Blue component [0., 1.].

a

float (Component), default: 1.0

Alpha (opacity) component [0., 1.].

property rgb

Red, green and blue floating point color components.

property rgba

Red, green, blue and alpha floating point color components.

property RGB

Red, green and blue integer color components.

property RGBA

Red, green, blue and alpha integer color components.

property str_hex

Hex color string.

property str_rgb

Red, green and blue floating point color components as string.

Output will be like 'rgb(<red>, <green>, <blue>)'.

property str_RGB

Red, green and blue integer color components as string.

Output will be like 'RGB(<red>, <green>, <blue>)'

property str_rgba

Red, green, blue and alpha floating point color components as string.

Output will be like 'rgba(<red>, <green>, <blue>, <alpha>)'.

property str_RGBA

Red, green, blue and alpha integer color components as string’

Output will be like 'RGBA(<red>, <green>, <blue>, <alpha>)'.

describe()[source]

Returns all possible definitions of the color.

class ColorGroup(**kwargs)[source]

Bases: Object

Group of predefined colors.

Each ColorGroup has a name and a set of colornames and referring Color Objects

name

str, optional

mapping

dict of Color objects, default: {}