Tuesday, October 1, 2013

Color Support

For a fairly long time, Factor has had support for RGB, HSV, and grayscale color spaces.

More recently, I got interested in colors, even having some fun by building color tab completion. We have now added support for CMYK, HSL, RYB, YIQ, and YUV color spaces. All colors support an alpha channel and conversion to and from RGB colors!

You could say two colors are equal if their RGB components are very, very, very close:

: color= ( color1 color2 -- ? )
    [ >rgba-components 4array ] bi@
    [ 0.00000000000001 ~ ] 2all? ;

Using that, you can write a test to confirm that our round trip through color spaces preserves the original color information:

{ t } [
    COLOR: sky-blue
    COLOR: sky-blue color=
] unit-test

This is now available in the development version of Factor!

Note: we also support basic color mixing, with the ability to do linear gradients between colors.

No comments: