packages feed

prizm 0.3.0.0 → 0.3.1.0

raw patch · 4 files changed

+48/−55 lines, 4 files

Files

CHANGES view
@@ -1,3 +1,8 @@+0.3.1.0+=======++- Cleaned up the color functions a bit and added a few more.+ 0.3.0.0 ======= 
README.md view
@@ -12,48 +12,27 @@ There is some overlap with the Haskell Colour Module that already exists; however, this library is filling a couple of needs the other doesn't satisfy. -## TODO--This module is getting kind of messy, I want to refactor how everything is organized. I also need to fix the types.- ## Supported Algorithms  - sRGB <-> CIE XYZ-- CIE XYZ <-> CIE L\*a\*b\*-- CIE L\*\a\*b <-> CIE L\*C\*h--## Roadmap--### 0.3.0.0--I really want to clean up the API - right now stuff is just "everywhere" and the different color spaces should have-their own modules with their own convenience conversions to/from RGB to minimize the amount of function chaining-required.--I also want to figure out a way of testing the lighten/darken, interpolation, and hue transformation functions.--### 0.2.1.0--Blending is now switched over to using CIE L*Ch color space for more accurate blending.--### 0.2.0.0-Functions for--- color blending-- tint / shade-- darken / lighten+- CIE XYZ <-> CIE L\*ab+- CIE L\*ab <-> CIE L\*Ch -### 0.1.0.4-Conversion functions for sRGB to HEX.+## Supported Functions -### 0.1.0.3-All color types should have instances for Functor so fmap can work over their values.-All color types should have instances for Applicative to make computations cleaner.+- Color interpolation+- Tinting / Darkening+- Lightness+- Hue+- Chroma/Saturation -### 0.1.0.2-Make sure all of the conversion formulas convert losslessly at an acceptable level of precision.+All of these functions operate on color within the CIE L\*Ch representation. The percentage values may range between+-100 and 100.  [General Color Formulas, Data, and Algorithms](http://www.brucelindbloom.com/index.html?Info.html)+ [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](https://github.com/mikeemoo/ColorJizz-PHP/blob/master/src/MischiefCollective/ColorJizz/ColorJizz.php)
prizm.cabal view
@@ -1,11 +1,11 @@ Name:                prizm-Version:             0.3.0.0+Version:             0.3.1.0 Synopsis:            A haskell library for computing with colors -Description:         Prizm can convert between many different color-                     representations; notably the sRGB and CIE-                     representations. Future versions will-                     have implementations for mutating colors as well.+Description:         Prizm is a library for converting between+                     different color representations and mutating+                     colors (interpolation, lightness, hue, chroma,+                     tint/shade).  Homepage:            https://github.com/ixmatus/prizm License:             BSD3@@ -55,7 +55,6 @@   hs-source-dirs: tests   main-is:        QC.hs   other-modules:  QC.SRGB---                  QC.Text    ghc-options:     -Wall -threaded -rtsopts
src/Data/Prizm/Color.hs view
@@ -1,11 +1,19 @@-module Data.Prizm.Color where+module Data.Prizm.Color (+  (<|>)+, shade+, tint+, lightness+, chroma+, hue+, interpolate+) where -import Control.Applicative+import Control.Applicative hiding ((<|>))  import Data.Prizm.Types  pct :: Integer -> Double-pct = (/100) . fromIntegral . (max 0) . (min 100)+pct = (/100) . fromIntegral . (max (-100)) . (min 100)  pctClamp :: Integer -> Integer pctClamp i = max (min i 100) 0@@ -14,8 +22,8 @@ clamp i clmp = max (min i clmp) 0.0  -- | Blend two colors using an interpolation value of 50%.-(<|>) :: (CIELCH Double, CIELCH Double) -> CIELCH Double-(<|>) = interpolate 50+(<|>) :: CIELCH Double -> CIELCH Double -> CIELCH Double+(<|>) l r = interpolate 50 (l,r)  -- | Shade a color by blending it using a weight and the color black. shade :: CIELCH Double -> Percent -> CIELCH Double@@ -25,17 +33,19 @@ tint :: CIELCH Double -> Percent -> CIELCH Double tint c w = interpolate (pctClamp w) (c, CIELCH 100.0 0.0 360.0) --- | Darken a color by converting it to CIE L*a*b* first, multiplying--- it by the weight, and then subtracting that value from the original--- L* value and converting the whole back to XYZ.-darken :: CIELCH Double -> Percent -> CIELCH Double-darken (CIELCH l c h) w = (CIELCH (l - (l*(pct (pctClamp w)))) c h)+-- | Darken a color.+lightness :: CIELCH Double -> Percent -> CIELCH Double+lightness (CIELCH l c h) w = (CIELCH (clamp (l + (100*(pct (pctClamp w)))) 100.0) c h) --- | Lighten a color by converting it to CIE L*a*b* first, multiplying--- it by the weight, and then adding that value to the original L*--- value and converting the whole back to XYZ.-lighten :: CIELCH Double -> Percent -> CIELCH Double-lighten (CIELCH l c h) w = (CIELCH (l + (l*(pct (pctClamp w)))) c h)+-- | Change the hue of a color.+hue :: CIELCH Double -> Percent -> CIELCH Double+hue (CIELCH l c h) w = (CIELCH l c (clamp (h + (360*(pct (pctClamp w)))) 360.0))++-- | Change the saturation/chroma of a color. A maximum chroma value+-- of 120 is assumed here, anything more is generally considered out+-- of gamut.+chroma :: CIELCH Double -> Percent -> CIELCH Double+chroma (CIELCH l c h) w = (CIELCH l (clamp (c + (120*(pct (pctClamp w)))) 120.0) h)  -- | Interpolate two colors --