Library for color manipulation. Contains definitions for Lab, LCh, Cmy(K), CubeHelix, Grey, Hcl, Hsl(A), Hsv(A), Rgb(A), Xyz and Yxy as well as alpha versions of the sames and color parsing.

To install, run:

haxelib install thx.color 0.19.1 

See using Haxelib in Haxelib documentation for more information.


Build Status

Color library for Haxe. Supports the following color spaces:

  • Lab (AKA Lab)
  • LCh (AKA HCL)
  • Luv (or LUV)
  • Cmy
  • Cmyk
  • CubeHelix
  • Grey
  • Hsl(a)
  • Hsv(a) (AKA HSB)
  • HunterLab
  • Rgb(a)
  • Rgbx(a) (an high resolution version of RGB)
  • Temperature
  • Xyz
  • Yuv
  • Yxy

With conversion from/to any color space (notice that you can lose some information in the conversion).


API uses abstracts to make it easy to create colors from strings and numbers.

    var rgb : Rgb = "#cf8700";

Some examples from Demo.

Hsl Rainbow

var left  : Hsl = 'hsl(0,100%,0%)',
    right : Hsl = 'hsl(359.99,100%,0%)';
return function(x : Float, y : Float) : Rgb {
  return left.interpolate(right, x).lighter(y);

Alt text

Hsv Interpolation

var left  : Hsv = 'hsv(160deg,100%,63%)',
    right : Hsv = 'hsv(345deg,88%,77%)';
return function(t : Float) : Rgb
    return (left : Hsv).interpolate(right, t);

Alt text

Lighter Rgb

var left : Rgb = '#0000ff';
return left.lighter;

Alt text

Named Colors Table

var columns = 5,
    colors  = Color.names.keys().toArray().filter(function(n) return n.indexOf(' ') < 0),
    cellw   = w / columns,
    cellh   = h / Math.ceil(colors.length / columns);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = '${Math.round(cellh*0.4)}px Verdana, sans-serif';
colors.mapi(function(name, i) {
    var col   = i % columns,
        row   = Math.floor(i / columns),
        color = Color.names.get(name);

    ctx.fillStyle = color.toString();
    ctx.fillRect(col * cellw, row * cellh, cellw, cellh);

    ctx.fillStyle = color.toRgbx()
        Math.round(col * cellw + cellw / 2) + 0.5,
        Math.round(row * cellh + cellh / 2) + 0.5,
color table

To run Demo, you need nodejs and the Canvas library (npm install canvas);

Note: API might still change before version 1.


From the command line just type:

haxelib install thx.color

To use the dev version do:

haxelib git thx.color
1 year ago

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser!

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github