palette icon indicating copy to clipboard operation
palette copied to clipboard

Add color systems

Open tesk9 opened this issue 5 years ago • 1 comments

Which color systems should this package support?

tesk9 avatar Dec 13 '19 23:12 tesk9

Short answer: CIE-LAB and CIE-LCH.

Long answer: I noticed that your maths functions are not very nice. While looking into algorithms for adding and blending colors, I found out that CIE-LAB is a good system for that(That's the system Photoshop and GIMP are using). There was just one small downside: Calculating the middle of two colors sometimes returns a grayish color. To fix that, CIE-LCH was invented.

For the actual implementation, you can use noahzgordon/elm-color-extra to convert to LAB and then define the following functions:

toCIELCH =
    Convert.colorToLab
        >> (\{ l, a, b } ->
            { l = l
            , c = sqrt (a * a + b * b)
            , h = atan2 b a
            }
        )

fromCIELCH =
    Convert.colorFromLab
        (\{ l, c, h } ->
            { l = l
            , a = c * cos h
            , b = c * sin h
            }
        )
            >> Convert.labToColor

Orasund avatar May 17 '20 14:05 Orasund