Home

Awesome

<img src="docs/chromaBanner.png">

Chroma - Everything you want to do with colors.

Github Actions

API reference

This library has no dependencies other than the Nim standard library.

About

This library works with colors and color spaces. Easily parse and transform colors. Many different color spaces. Optimized, fast and consistent.

Parse/Format

Common color parsers and formatters:

Color Spaces

Conversion from and to these colors spaces:

The default type is an RGB based type using float32 as its base type (with values ranging from 0 to 1) and is called Color. All the above color spaces have corresponding type names of Color<ColorSpaceName>, where ColorSpaceName is the name in the bullet points above (unless specified by "type:" in parenthesis).

Convenience procs to convert from and to the default type Color are provided in the form of

and the inverse:

and using the field names:

Color Functions

You can use these to change colors you already have

A distance function is provided that implements CIEDE2000 color difference formula

This distance is designed to be perceptually uniform and it can be used to answer the question: "What is a set of colors that are imperceptibly/acceptably close to a given reference?". A value of 5.0 is used as reference in github linguist library: any color with distance less than 5.0 from one of the existing colors is not allowed.

Example

import chroma

let
    a = color(0.7,0.8,0.9)
    b = color(0.2,0.3,0.4,0.5)

echo a.toHex()
echo parseHex("BADA55")
echo parseHtmlName("red")
echo hsv(b).color()
echo a.darken(0.2)
echo mix(a, b)