animator.graphics.color

Colors make the world go round. In animator, colors are represented as skia.Color4f objects from the underlying Skia library. The skia.Color4f class provides an object-oriented interface to a color’s red, green, blue, and alpha channels, each with a value between 0 and 1. It can also be used as a list of 4 floats representing the same channels. You can also use a tuple of 4 floats in most places where a skia.Color4f is expected.

Some colors are predefined:

BLACK

BLUE

CYAN

GRAY

GREEN

LIME

MAGENTA

MAROON

NAVY

OLIVE

ORANGE

PURPLE

RED

SILVER

TEAL

WHITE

YELLOW

TRANSPARENT

Some examples and possible mistakes to avoid:

>>> color(127.5, 255, 0, 1)  # simplest way to create a color, red[0, 255], green[0, 255], blue[0, 255], alpha[0, 1]
Color4f(0.5, 1, 0, 1)
>>> color(255.0)  # grayscale, if a single float is given
Color4f(1, 1, 1, 1)
>>> color(255)  # if an int is given, it is passed as a packed 32-bit ARGB value
Color4f(0, 0, 1, 0)
>>> color('MarOon')  # case-insensitive color name
Color4f(0.501961, 0, 0, 1)
>>> color('red50')  # material color shade
Color4f(1, 0.921569, 0.933333, 1)
>>> color('limeA700')  # material color accent
Color4f(0.682353, 0.917647, 0, 1)
>>> color(r'r G b ( 50% 0, 0.0\0.5)')  # strangely formatted CSS functional notation
Color4f(0.5, 0, 0, 0.5)
>>> color('420, 42, 3.14, max=(420, 42, 3.14), a=0.123)  # white, but with a custom max value and alpha
Color4f(1, 1, 1, 0.123)