Skip to main content

Color handling made simple.

Project description

Chroma

Chroma is a Python module for handling colors with ease. Chroma supports HEX, RGB, HLS and HSV color coordinates and can seamlessly support alpha.

Quickstart

import chroma

# Create a Color object
color = chroma.Color('#00FF00')

# Get RGB, HLS, and HSV in either float or 0 - 255 (8bit)
# Also, HEX
color.rgb # (0.0, 1.0, 0.0)
color.hls # (0.3333333333333333, 0.5, 1.0)
color.rgb256 # (0, 255, 0)
color.hex = # '#00FF00'

# Set RGB, HLS, HSV (float or 256) and HEX
color.rgb256 = (255, 0, 0)
color.hls = (0.0, 1.0, 0.0)

BSD licensed. Hosted on Github and available on PyPI.

Currently Supports

  • Hex (#rrggbb, #rrggbbaa)

  • RGB (float, 256)

  • HLS (float)

  • HSV (float)

  • Alpha

  • Direct modification of Red, Green, Blue, Lightness, Hue, Saturation (HLS, HSV), Value

Roadmap

  • More Hex formats (#RGB, #RRRGGGBBB, #RRRRGGGGBBBB)

  • Color dectection in images

Documentation

Install Chroma with Pip:

pip install chroma

To handle various color coordinates, Chroma uses a Color object. A Color object can be initialized with any available color format (HEX, RGB, RGB256, HLS, HSV).

c = chroma.Color()  # defaults to white
c = chroma.Color('#557799')  # default format is HEX
c = chroma.Color((0.583, 0.444, 0.60), 'HSV')  # create Color object with HLS

To modify or access the color in any format, use Color’s properties.

c.hex
c.rgb
c.rgb256
c.hls
c.hsv

c.hex = '#557799'
c.hsv = (0.583, 0.444, 0.60)
...

Chroma Colors also support alpha. A Color object’s alpha is set to None by default, and as long as it is None it will be ignored. If it is included when setting the color, it will be added to the getters returns as well.

c.hex = '#557799'
c.rgb  # (0.3333, 0.4666, 0.6)

c.hex = '#557799FF'
c.rgb  # (0.3333, 0.4666, 0.6, 1.0)
c.hls  # (0.5833, 0.4666, 0.2857, 1.0)

c.alpha = None
c.rgb  # (0.3333, 0.4666, 0.6)

To simplify modifying color values, Chroma supports direct modification of color coordinates.

c.red *= 1.1
c.green *= 1.1
c.blue *= 1.1

c.hue *= 1.1
c.lightness *= 1.1
c.hls_saturation *= 1.1

c.value *= 1.1
c.hsv_saturation *= 1.1

History

0.1.3 (2013-01-01)

  • Direct modification of color coordinates

0.1.2 (2012-12-28)

  • Remove HLS256, HSV256 (critical bug)

  • Alpha support

  • Add RGB, RGB256, HLS, HSV as formats for Color initialization

  • Bug fixes

0.1.1 (2012-12-16)

  • HLS, HSV Support

  • API changes (setter methods)

  • Bug Fixes

  • Update to README

0.1.0 (2012-12-15)

  • Initial Release

  • RGB and Hex support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Chroma-0.1.3.tar.gz (5.0 kB view details)

Uploaded Source

File details

Details for the file Chroma-0.1.3.tar.gz.

File metadata

  • Download URL: Chroma-0.1.3.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Chroma-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3bd56aed26f113158ef6d810abf4d49d5f39d5d13dd86c3f18c7017e0593b6e9
MD5 e94b675a1a5b26eb2356297f200635e0
BLAKE2b-256 36bb4f9523c45448c8839220f8221d0fbd550ee17d51fbaa52f634a60b2eab8d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page