Cope 2.5.0
My personal "standard library" of all the generally useful code I've written for various projects over the years
Loading...
Searching...
No Matches

◆ parse_color()

'type(rtn)' Cope.colors.parse_color ( args,
Literal['html', 'rgb', 'rgba', 'opengl', 'hsv', 'hls', 'yiq']  rtn = 'rgb',
**  kwargs 
)

One color function to rule them all! Parses a color, however you care to pass it, and returns it however you like.

Input Schemes:

  • Positional parameters
    • parse_color(255, 255, 255, 255)
    • parse_color(255, 255, 255)
  • tuple or list
    • parse_color((255, 255, 255, 255))
    • parse_color((255, 255, 255))
  • Keyword parameters/dict
    • parse_color(r=255, g=255, b=255, a=255)
    • parse_color({'r': 255, 'g': 255, 'b': 255, 'a': 255})
    • parse_color(red=255, green=255, blue=255, alpha=255)
    • parse_color({'red': 255, 'green': 255, 'blue': 255, 'alpha': 255})
  • OpenGL style colors (between -1 and 1)
    • parse_color(1., 1., 1.)
    • parse_color((1., 1., 1.))
  • Hex colors
    • parse_color('#FFFFFF')
    • parse_color('#ffffff')
  • Named colors
    • parse_color('white')
  • "Random" distinct colors
    • parse_color(1)
  • Anything that has r, g, b attributes or red, green, blue attributes (callable or not)
    • parse_color(QColor(255, 255, 255))

Return Schemes:

  • 'html'
    • #FFFFFF
  • 'rgb'
    • (255, 255, 255)
  • 'rgba'
    • (255, 255, 255, 255)
  • 'opengl'
    • (1., 1., 1., 1.)
  • 'hsv'
    • (0., 0., 1.)
  • 'hls'
    • (0., 1., 0.)
  • 'yiq'
    • (1., 0., 0.)

If a is not provided, but it is selected to be returned, it defaults to the max (255, usually)

NOTE: Don't pass OpenGL colors as dicts or as keyword arguements. It will interpret them as RGBA parameters.

Definition at line 61 of file colors.py.