项目作者: ixmatus

项目描述 :
Convert colors to different color spaces, interpolate colors, and transform colors
高级语言: Haskell
项目地址: git://github.com/ixmatus/prizm.git
创建时间: 2013-05-09T19:18:06Z
项目社区:https://github.com/ixmatus/prizm

开源协议:BSD 3-Clause "New" or "Revised" License

下载


Welcome!

Hackage Version
Travis CI Status

prizm is a Haskell library for transforming colors. Specifically, providing
functions for transforming between different color spaces (CIE and sRGB),
interpolating colors and adjusting the tint, shade, hue, or lightness of a
color.

The inspiration for this library came from a desire to blend two colors
represented in the sRGB color space. My research about color blending and
color space representation in the computer led me to the conclusion that the
CIE L*Ch color space is the most effective for blending because it most
accurately represents how the human eye sees hue and therefore preserves (and
blends) hue the most accurately.

Quickstart

  1. {-# LANGUAGE ScopedTypeVariables #-}
  2. import Data.Convertible
  3. import Data.Prizm.Color
  4. import Data.Prizm.Color.CIE as CIE
  5. main :: IO ()
  6. main = do
  7. -- Convert RGB colors to the CIE.LCH color space
  8. let green :: CIE.LCH = convert $ mkRGB 102 255 0
  9. pink :: CIE.LCH = convert $ mkRGB 255 0 255
  10. -- Blend with a weight of 50%
  11. blended50 = pink <~> green
  12. -- Blend with a weight of 20%
  13. blended20 = interpolate 20 (pink,green)
  14. -- Print the CIE.LCH representation
  15. putStrLn $ show blended50
  16. -- Print the RGB representation of the blended color
  17. putStrLn . show $ ((convert blended20) :: RGB)
  18. -- Print the RGB color in a hexadecimal encoding
  19. putStrLn . show $ ((convert blended20) :: HexRGB)

Supported Algorithms

  • sRGB <-> CIE XYZ
  • CIE XYZ <-> CIE L*ab
  • CIE L*ab <-> CIE L*Ch

Supported Functions

  • Color interpolation
  • Tinting / Darkening
  • Lightness
  • Hue
  • Chroma/Saturation

Examples

Example blending with CIELCH converted back to RGB.

References