ll.color

RGB color values and color model conversion

Home › Python software › ll.colorText · XIST · Python

ll.color provides classes and functions for handling RGB colors.

class Color​(tuple):

A Color object represents a color with red, green and blue components.

def __new__​(cls, r=0, g=0, b=0, a=255):

Create a Color with the 8 bit red, green, blue and alpha components r, g, b and a. Values will be clipped to the range [0; 255].

def __repr__​(self):

def __str__​(self):

self formatted as a CSS color string.

def r​(self):

The red value as an int between 0 and 255.

def g​(self):

The green value as an int between 0 and 255.

def b​(self):

The blue value as an int between 0 and 255.

def a​(self):

The alpha value as an int between 0 and 255.

def rgb​(self):

The red, green and blue value as a float tuple with values between 0.0 and 1.0.

def rgba​(self):

The red, green, blue and alpha value as a float tuple with values between 0.0 and 1.0.

def hsv​(self):

self as a HSV ("hue, saturation, value") triple. All three values are between 0.0 and 1.0.

def hsva​(self):

self as a HSV+alpha ("hue, saturation, value, alpha") tuple. All four values are between 0.0 and 1.0.

def hls​(self):

self as a HLS ("hue, luminance, saturation") triple. All three values are between 0.0 and 1.0.

def hlsa​(self):

self as a HLS+alpha ("hue, luminance, saturation, alpha") tuple. All four values are between 0.0 and 1.0.

def lum​(self):

The luminance value from hls.

def combine​(self, r=None, g=None, b=None, a=None):

Return a copy of self with some of the values replaced by the arguments.

def witha​(self, a):

Return a copy of self with the alpha value replaced with a.

def withlum​(self, lum):

Return a copy of self with the luminosity replaced with lum.

def abslum​(self, f):

Return a copy of self with f added to the luminocity.

def rellum​(self, f):

Return a copy of self where the luminocity has been modified: If f if positive the luminocity will be increased, with f==1 giving a luminocity of 1. If f is negative, the luminocity will be decreased with f==-1 giving a luminocity of 0. f==0 will leave the luminocity unchanged.

def __add__​(self, other):

def __mul__​(self, factor):

def __rmul__​(self, factor):

def __truediv__​(self, factor):

def __floordiv__​(self, factor):

def __mod__​(self, other):

Blends self with the background color other according to the SVG specification

def css​(value):

def dist​(c1, c2):

Return the distance between two colors.

def multiply​(c1, c2):

Multiplies the colors c1 and c2.

def screen​(c1, c2):

Does a negative multiplication of the colors c1 and c2.

def mix​(*args):

Calculates a weighted mix of the colors from args. Items in args are either colors or weights.