Colorzero

2.0 · active · verified Thu Apr 16

Colorzero is a Python library designed for simple and 'pythonic' color manipulation. It features a comprehensive `Color` class capable of converting between various color representations and calculating color differences. The library utilizes immutable `Color` objects, which are descendents of `namedtuple`, necessitating a specific approach to color manipulation. The current version is 2.0, last released in March 2021.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating `Color` objects using various constructors and manipulating them by producing new instances through arithmetic operations with manipulation classes.

from colorzero import Color, Green, Lightness

# Create a color from various inputs
red = Color('red')
blue = Color(0, 0, 1) # RGB floats (0.0-1.0)
magenta_html = Color('#ff00ff')

# Color objects are immutable; operations return new objects
c = Color('yellow')
print(f"Initial color: {c}")

# Add green component
c_more_green = c + Green(0.1)
print(f"After adding green: {c_more_green}")

# Reduce lightness by multiplying
c_darker = c_more_green * Lightness(0.5)
print(f"After making darker: {c_darker}")

# Convert to different representations
print(f"HTML: {c_darker.html}")
print(f"RGB bytes: {c_darker.rgb_bytes}")
print(f"HLS: {c_darker.hls}")

view raw JSON →