https://github.com/ixmatus/prizm
Convert colors to different color spaces, interpolate colors, and transform colors
https://github.com/ixmatus/prizm
colors colorspace haskell-library
Last synced: 3 months ago
JSON representation
Convert colors to different color spaces, interpolate colors, and transform colors
- Host: GitHub
- URL: https://github.com/ixmatus/prizm
- Owner: ixmatus
- License: bsd-3-clause
- Created: 2013-05-09T19:18:06.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2017-04-29T20:51:17.000Z (about 9 years ago)
- Last Synced: 2025-12-08T10:48:59.358Z (6 months ago)
- Topics: colors, colorspace, haskell-library
- Language: Haskell
- Homepage:
- Size: 116 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Welcome!


`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
```haskell
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Convertible
import Data.Prizm.Color
import Data.Prizm.Color.CIE as CIE
main :: IO ()
main = do
-- Convert RGB colors to the CIE.LCH color space
let green :: CIE.LCH = convert $ mkRGB 102 255 0
pink :: CIE.LCH = convert $ mkRGB 255 0 255
-- Blend with a weight of 50%
blended50 = pink <~> green
-- Blend with a weight of 20%
blended20 = interpolate 20 (pink,green)
-- Print the CIE.LCH representation
putStrLn $ show blended50
-- Print the RGB representation of the blended color
putStrLn . show $ ((convert blended20) :: RGB)
-- Print the RGB color in a hexadecimal encoding
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](./blending-test.html).
# References
- [General Color Formulas, Data, and Algorithms](http://www.brucelindbloom.com)
- [CIE Conversion Mathematics](http://rip94550.wordpress.com/2011/07/04/color-cielab-and-tristimulus-xyz/)
- [Conversion Algorithm Sources](http://www.easyrgb.com/index.php?X=MATH&H=01)
- [Good list of useful color manipulation formulas](https://github.com/mikeemoo/ColorJizz-PHP/blob/master/src/MischiefCollective/ColorJizz/ColorJizz.php)