diff --git a/haddock.txt b/haddock.txt index 462ffa1..aad0408 100644 --- a/haddock.txt +++ b/haddock.txt @@ -1,7 +1,10 @@ 100% ( 22 / 22) in 'Reanimate.Effect' - 92% ( 12 / 13) in 'Reanimate.ColorMap' + 100% ( 17 / 17) in 'Reanimate.Parameters' + 100% ( 13 / 13) in 'Reanimate.ColorMap' + 100% ( 12 / 12) in 'Reanimate.ColorComponents' + 100% ( 9 / 9) in 'Reanimate.Constants' + 94% (144 /154) in 'Reanimate' 88% ( 7 / 8) in 'Reanimate.Transition' - 86% (134 /155) in 'Reanimate' 85% ( 47 / 55) in 'Reanimate.Svg.Constructors' 77% ( 33 / 43) in 'Reanimate.Animation' 73% ( 8 / 11) in 'Reanimate.Ease' @@ -11,9 +14,9 @@ 50% ( 1 / 2) in 'Reanimate.Builtin.CirclePlot' 44% ( 4 / 9) in 'Reanimate.LaTeX' 42% ( 17 / 40) in 'Reanimate.GeoProjection' - 42% ( 5 / 12) in 'Reanimate.ColorComponents' 41% ( 45 /111) in 'Reanimate.Scene' 38% ( 3 / 8) in 'Reanimate.Builtin.Documentation' + 33% ( 4 / 12) in 'Reanimate.Render' 28% ( 5 / 18) in 'Reanimate.Svg' 25% ( 1 / 4) in 'Reanimate.Builtin.Slide' 17% ( 1 / 6) in 'Reanimate.Svg.BoundingBox' @@ -26,16 +29,13 @@ 0% ( 0 / 37) in 'Reanimate.Internal.CubicBezier' 0% ( 0 / 20) in 'Reanimate.Math.Compatible' 0% ( 0 / 19) in 'Reanimate.Morph.Rigid' - 0% ( 0 / 17) in 'Reanimate.Parameters' 0% ( 0 / 13) in 'Reanimate.Morph.LeastWork' 0% ( 0 / 13) in 'Reanimate.Morph.Common' - 0% ( 0 / 12) in 'Reanimate.Render' 0% ( 0 / 10) in 'Reanimate.Math.Render' 0% ( 0 / 10) in 'Reanimate.ColorSpace' 0% ( 0 / 10) in 'Reanimate.Builtin.TernaryPlot' 0% ( 0 / 9) in 'Reanimate.Povray' 0% ( 0 / 9) in 'Reanimate.Math.Smooth' - 0% ( 0 / 9) in 'Reanimate.Constants' 0% ( 0 / 8) in 'Reanimate.Misc' 0% ( 0 / 8) in 'Reanimate.Math.Balloon' 0% ( 0 / 8) in 'Reanimate.Chiphunk' diff --git a/haddock_badge.json b/haddock_badge.json index 89b158d..0e2504c 100644 --- a/haddock_badge.json +++ b/haddock_badge.json @@ -1 +1 @@ - { "schemaVersion": 1, "label": "api docs", "message": "30%", "color": "success" } + { "schemaVersion": 1, "label": "api docs", "message": "34%", "color": "success" } diff --git a/reanimate-0.4.1.0-inplace/Reanimate.ColorComponents.hs.html b/reanimate-0.4.1.0-inplace/Reanimate.ColorComponents.hs.html index 26a2a86..3256f3c 100644 --- a/reanimate-0.4.1.0-inplace/Reanimate.ColorComponents.hs.html +++ b/reanimate-0.4.1.0-inplace/Reanimate.ColorComponents.hs.html @@ -18,104 +18,134 @@ span.spaces { background: white }
1 {-# LANGUAGE RecordWildCards #-} - 2 module Reanimate.ColorComponents where - 3 - 4 import Codec.Picture - 5 import Codec.Picture.Types - 6 import Data.Colour - 7 import Data.Colour.CIE - 8 import Data.Colour.CIE.Illuminant (d65) - 9 import Data.Colour.RGBSpace - 10 import Data.Colour.RGBSpace.HSV - 11 import Data.Colour.SRGB - 12 import Data.Fixed - 13 import Reanimate.Ease - 14 - 15 data ColorComponents = ColorComponents - 16 { colorUnpack :: Colour Double -> (Double, Double, Double) - 17 , colorPack :: Double -> Double -> Double -> Colour Double } - 18 - 19 -- | > interpolate rgbComponents yellow blue - 20 -- - 21 -- <<docs/gifs/doc_rgbComponents.gif>> - 22 rgbComponents :: ColorComponents - 23 rgbComponents = ColorComponents rgbUnpack sRGB - 24 where - 25 rgbUnpack :: Colour Double -> (Double, Double, Double) - 26 rgbUnpack c = - 27 case toSRGB c of - 28 RGB r g b -> (r,g,b) - 29 - 30 -- | > interpolate hsvComponents yellow blue - 31 -- - 32 -- <<docs/gifs/doc_hsvComponents.gif>> - 33 hsvComponents :: ColorComponents - 34 hsvComponents = ColorComponents unpack pack - 35 where - 36 unpack = hsvView.toSRGB - 37 pack a b c = uncurryRGB sRGB $ hsv a b c - 38 - 39 -- | > interpolate labComponents yellow blue - 40 -- - 41 -- <<docs/gifs/doc_labComponents.gif>> - 42 labComponents :: ColorComponents - 43 labComponents = ColorComponents unpack pack - 44 where - 45 unpack = cieLABView d65 - 46 pack = cieLAB d65 - 47 - 48 -- | > interpolate xyzComponents yellow blue - 49 -- - 50 -- <<docs/gifs/doc_xyzComponents.gif>> - 51 xyzComponents :: ColorComponents - 52 xyzComponents = ColorComponents cieXYZView cieXYZ - 53 - 54 -- | > interpolate lchComponents yellow blue - 55 -- - 56 -- <<docs/gifs/doc_lchComponents.gif>> - 57 lchComponents :: ColorComponents - 58 lchComponents = ColorComponents unpack pack - 59 where - 60 toDeg,toRad :: Double -> Double - 61 toRad deg = deg/180 * pi - 62 toDeg rad = rad/pi * 180 - 63 unpack :: Colour Double -> (Double, Double, Double) - 64 unpack color = - 65 let (l,a,b) = cieLABView d65 color - 66 c = sqrt (a*a + b*b) - 67 h :: Double - 68 h = (toDeg(atan2 b a) + 360) `mod'` 360 - 69 isZero = round (c*10000) == (0::Integer) - 70 in (l, c, if isZero then 0/0 else h) - 71 pack l c h = - 72 cieLAB d65 l (cos (toRad h) * c) (sin (toRad h) * c) - 73 - 74 interpolate :: ColorComponents -> Colour Double -> Colour Double -> (Double -> Colour Double) - 75 interpolate ColorComponents{..} from to = \d -> - 76 colorPack (a1 + (a2-a1)*d) (b1 + (b2-b1)*d) (c1 + (c2-c1)*d) - 77 where - 78 (a1,b1,c1) = colorUnpack from - 79 (a2,b2,c2) = colorUnpack to - 80 - 81 interpolateRGB8 :: ColorComponents -> PixelRGB8 -> PixelRGB8 -> (Double -> PixelRGB8) - 82 interpolateRGB8 comps from to = toRGB8 . interpolate comps (fromRGB8 from) (fromRGB8 to) - 83 - 84 interpolateRGBA8 :: ColorComponents -> PixelRGBA8 -> PixelRGBA8 -> (Double -> PixelRGBA8) - 85 interpolateRGBA8 comps from to = \t -> - 86 case interp t of - 87 PixelRGB8 r g b -> - 88 let alpha = fromToS (fromIntegral $ pixelOpacity from) (fromIntegral $ pixelOpacity to) t - 89 in PixelRGBA8 r g b (round alpha) - 90 where - 91 interp = interpolateRGB8 comps (dropTransparency from) (dropTransparency to) - 92 - 93 toRGB8 :: Colour Double -> PixelRGB8 - 94 toRGB8 c = PixelRGB8 r g b - 95 where - 96 RGB r g b = toSRGBBounded c - 97 - 98 fromRGB8 :: PixelRGB8 -> Colour Double - 99 fromRGB8 (PixelRGB8 r g b) = sRGB24 r g b + 2 {- | + 3 Colors are three dimensional and can be projected into many color spaces + 4 with different properties. + 5 + 6 Interpolating directly in the RGB color space is unintuitive and rarely useful. + 7 If you want to transition through color, you most likely want either the XYZ space + 8 (for physically accurate color transitions) or the LAB space (for esthetically + 9 pleasing colors). + 10 -} + 11 module Reanimate.ColorComponents + 12 ( ColorComponents(..) + 13 , rgbComponents + 14 , hsvComponents + 15 , labComponents + 16 , xyzComponents + 17 , lchComponents + 18 , interpolate + 19 , interpolateRGB8 + 20 , interpolateRGBA8 + 21 , toRGB8 + 22 , fromRGB8 + 23 ) where + 24 + 25 import Codec.Picture + 26 import Codec.Picture.Types + 27 import Data.Colour + 28 import Data.Colour.CIE + 29 import Data.Colour.CIE.Illuminant (d65) + 30 import Data.Colour.RGBSpace + 31 import Data.Colour.RGBSpace.HSV + 32 import Data.Colour.SRGB + 33 import Data.Fixed + 34 import Reanimate.Ease + 35 + 36 -- | Constructor and destructor for color's three components. + 37 data ColorComponents = ColorComponents + 38 { colorUnpack :: Colour Double -> (Double, Double, Double) + 39 -- ^ Unpack a color into its three components. + 40 , colorPack :: Double -> Double -> Double -> Colour Double + 41 -- ^ Restore a color from three coordinates. + 42 } + 43 + 44 -- | > interpolate rgbComponents yellow blue + 45 -- + 46 -- <<docs/gifs/doc_rgbComponents.gif>> + 47 rgbComponents :: ColorComponents + 48 rgbComponents = ColorComponents rgbUnpack sRGB + 49 where + 50 rgbUnpack :: Colour Double -> (Double, Double, Double) + 51 rgbUnpack c = + 52 case toSRGB c of + 53 RGB r g b -> (r,g,b) + 54 + 55 -- | > interpolate hsvComponents yellow blue + 56 -- + 57 -- <<docs/gifs/doc_hsvComponents.gif>> + 58 hsvComponents :: ColorComponents + 59 hsvComponents = ColorComponents unpack pack + 60 where + 61 unpack = hsvView.toSRGB + 62 pack a b c = uncurryRGB sRGB $ hsv a b c + 63 + 64 -- | > interpolate labComponents yellow blue + 65 -- + 66 -- <<docs/gifs/doc_labComponents.gif>> + 67 labComponents :: ColorComponents + 68 labComponents = ColorComponents unpack pack + 69 where + 70 unpack = cieLABView d65 + 71 pack = cieLAB d65 + 72 + 73 -- | > interpolate xyzComponents yellow blue + 74 -- + 75 -- <<docs/gifs/doc_xyzComponents.gif>> + 76 xyzComponents :: ColorComponents + 77 xyzComponents = ColorComponents cieXYZView cieXYZ + 78 + 79 -- | > interpolate lchComponents yellow blue + 80 -- + 81 -- <<docs/gifs/doc_lchComponents.gif>> + 82 lchComponents :: ColorComponents + 83 lchComponents = ColorComponents unpack pack + 84 where + 85 toDeg,toRad :: Double -> Double + 86 toRad deg = deg/180 * pi + 87 toDeg rad = rad/pi * 180 + 88 unpack :: Colour Double -> (Double, Double, Double) + 89 unpack color = + 90 let (l,a,b) = cieLABView d65 color + 91 c = sqrt (a*a + b*b) + 92 h :: Double + 93 h = (toDeg(atan2 b a) + 360) `mod'` 360 + 94 isZero = round (c*10000) == (0::Integer) + 95 in (l, c, if isZero then 0/0 else h) + 96 pack l c h = + 97 cieLAB d65 l (cos (toRad h) * c) (sin (toRad h) * c) + 98 + 99 -- | Smoothly interpolate between two colors using the given color components. + 100 interpolate :: ColorComponents -> Colour Double -> Colour Double -> (Double -> Colour Double) + 101 interpolate ColorComponents{..} from to = \d -> + 102 colorPack (a1 + (a2-a1)*d) (b1 + (b2-b1)*d) (c1 + (c2-c1)*d) + 103 where + 104 (a1,b1,c1) = colorUnpack from + 105 (a2,b2,c2) = colorUnpack to + 106 + 107 -- | Convenience interpolation function for RGB8 values. + 108 interpolateRGB8 :: ColorComponents -> PixelRGB8 -> PixelRGB8 -> (Double -> PixelRGB8) + 109 interpolateRGB8 comps from to = toRGB8 . interpolate comps (fromRGB8 from) (fromRGB8 to) + 110 + 111 -- | Convenience interpolation function for RGBA8 values. + 112 interpolateRGBA8 :: ColorComponents -> PixelRGBA8 -> PixelRGBA8 -> (Double -> PixelRGBA8) + 113 interpolateRGBA8 comps from to = \t -> + 114 case interp t of + 115 PixelRGB8 r g b -> + 116 let alpha = fromToS (fromIntegral $ pixelOpacity from) (fromIntegral $ pixelOpacity to) t + 117 in PixelRGBA8 r g b (round alpha) + 118 where + 119 interp = interpolateRGB8 comps (dropTransparency from) (dropTransparency to) + 120 + 121 -- | Convenience function for expressing a color as an RGB8 value. + 122 toRGB8 :: Colour Double -> PixelRGB8 + 123 toRGB8 c = PixelRGB8 r g b + 124 where + 125 RGB r g b = toSRGBBounded c + 126 + 127 -- | Convenience function for expressing an RGB8 value as a color. + 128 fromRGB8 :: PixelRGB8 -> Colour Double + 129 fromRGB8 (PixelRGB8 r g b) = sRGB24 r g b