diff --git a/docs/gifs/doc_githubWhiteIcon.gif b/docs/gifs/doc_githubWhiteIcon.gif new file mode 100644 index 0000000..c927a47 Binary files /dev/null and b/docs/gifs/doc_githubWhiteIcon.gif differ diff --git a/docs/gifs/doc_ternaryPlot.gif b/docs/gifs/doc_ternaryPlot.gif index a4afc4b..3692b52 100644 Binary files a/docs/gifs/doc_ternaryPlot.gif and b/docs/gifs/doc_ternaryPlot.gif differ diff --git a/examples/doc_githubWhiteIcon.hs b/examples/doc_githubWhiteIcon.hs new file mode 100755 index 0000000..d8899c2 --- /dev/null +++ b/examples/doc_githubWhiteIcon.hs @@ -0,0 +1,12 @@ +#!/usr/bin/env stack +-- stack runghc --package reanimate +module Main (main) where + +import Reanimate +import Reanimate.Builtin.Documentation +import Reanimate.Builtin.Images + +main :: IO () +main = reanimate $ staticFrame 1 $ mkGroup + [ mkBackground "grey" + , githubWhiteIcon ] diff --git a/examples/doc_ternaryPlot.hs b/examples/doc_ternaryPlot.hs index e038685..31c8dbc 100755 --- a/examples/doc_ternaryPlot.hs +++ b/examples/doc_ternaryPlot.hs @@ -2,13 +2,15 @@ -- stack runghc --package reanimate module Main(main) where -import Reanimate hiding (raster) -import Reanimate.Builtin.Documentation -import Reanimate.Builtin.TernaryPlot -import Reanimate.ColorComponents -import Data.Colour.CIE -import Codec.Picture.Types +import Codec.Picture.Types +import Reanimate +import Reanimate.Builtin.Documentation +import Reanimate.Builtin.TernaryPlot main :: IO () -main = reanimate $ docEnv $ animate $ const $ - ternaryPlot 1024 (\a b c -> promotePixel $ toRGB8 $ cieXYZ a b c) +main = reanimate $ docEnv $ staticFrame 1 $ + ternaryPlot 100 $ \aCoord bCoord cCoord -> promotePixel $ + let red = round $ aCoord*255 + green = round $ bCoord*255 + blue = round $ cCoord*255 + in PixelRGB8 red green blue diff --git a/src/Reanimate/Builtin/Images.hs b/src/Reanimate/Builtin/Images.hs index d7ea351..d8fbe38 100644 --- a/src/Reanimate/Builtin/Images.hs +++ b/src/Reanimate/Builtin/Images.hs @@ -1,3 +1,14 @@ +{-| +Module : Reanimate.Builtin.Images +Copyright : Written by David Himmelstrup +License : Unlicense +Maintainer : lemmih@gmail.com +Stability : experimental +Portability : POSIX + +Collection of built-in images. + +-} module Reanimate.Builtin.Images ( svgLogo , haskellLogo @@ -46,6 +57,7 @@ githubIcon :: SVG githubIcon = unsafePerformIO $ embedImage "data/github-icon.svg" {-# NOINLINE githubWhiteIcon #-} +-- | <> githubWhiteIcon :: SVG githubWhiteIcon = unsafePerformIO $ embedImage "data/github-icon-white.svg" diff --git a/src/Reanimate/Builtin/TernaryPlot.hs b/src/Reanimate/Builtin/TernaryPlot.hs index cdfe9d3..9d787cc 100644 --- a/src/Reanimate/Builtin/TernaryPlot.hs +++ b/src/Reanimate/Builtin/TernaryPlot.hs @@ -1,19 +1,56 @@ -module Reanimate.Builtin.TernaryPlot where +{-| +Module : Reanimate.Builtin.TernaryPlot +Copyright : Written by David Himmelstrup +License : Unlicense +Maintainer : lemmih@gmail.com +Stability : experimental +Portability : POSIX + +Implementation of ternary plots: + +-} +module Reanimate.Builtin.TernaryPlot + ( ACoord + , BCoord + , CCoord + , ternaryPlot + -- , atCenter + -- , radius + , toCartesianCoords + , toOffsetCartesianCoords + , fromCartesianCoords + ) where import Codec.Picture import Graphics.SvgTree (Tree) import Reanimate.Raster import Reanimate.Svg --- (top, left, right) -- a+b+c=1 +-- | Left-most coordinate. type ACoord = Double +-- | Top-most coordinate. type BCoord = Double +-- | Right-most coordinate. type CCoord = Double --- Creates a centered ternary plot with a width of 5. -ternaryPlot :: Int -- ^ Pixels in the X-axis. - -> (ACoord -> BCoord -> CCoord -> PixelRGBA8) -> Tree +-- | Creates a centered ternary plot with a width of 5. +-- +-- Example: +-- +-- > ternaryPlot 100 $ \aCoord bCoord cCoord -> promotePixel $ +-- > let red = round $ aCoord*255 +-- > green = round $ bCoord*255 +-- > blue = round $ cCoord*255 +-- > in PixelRGB8 red green blue +-- +-- <> +ternaryPlot :: Int -- ^ Pixels in the X-axis. More pixels => higher quality. + -> (ACoord -> BCoord -> CCoord -> PixelRGBA8) + -- ^ a+b+c=1. A=1 is the left-most position, + -- B=1 is the top-most position, and + -- C=1 is the right-most position. + -> Tree ternaryPlot density fn = scaleToWidth stdWidth $ translate (-cX) (-cY) $ @@ -36,22 +73,27 @@ ternaryPlot density fn = then PixelRGBA8 0 0 0 0 else fn aCoord bCoord cCoord -atCenter :: Double -> Tree -> Tree -atCenter stdWidth = translate (-cX*stdWidth) (-cY*stdWidth) - where - (cX, cY) = toCartesianCoords (1/3) (1/3) +-- atCenter :: Double -> Tree -> Tree +-- atCenter stdWidth = translate (-cX*stdWidth) (-cY*stdWidth) +-- where +-- (cX, cY) = toCartesianCoords (1/3) (1/3) -radius :: Double -radius = sqrt (cX*cX + cY*cY) - where - (cX, cY) = toCartesianCoords (1/3) (1/3) +-- radius :: Double +-- radius = sqrt (cX*cX + cY*cY) +-- where +-- (cX, cY) = toCartesianCoords (1/3) (1/3) +-- | Compute the XY coordinates from ternary coordinates. +-- Note that @CCoord@ is given because @a+b+c=1@. toCartesianCoords :: ACoord -> BCoord -> (Double, Double) toCartesianCoords a b = (x, y) where x = (a+2*b)/2 y = (sqrt 3 / 2) * a +-- | Compute the XY coordinates relative from the center of the +-- ternary plot. +-- Note that @CCoord@ is given because @a+b+c=1@. toOffsetCartesianCoords :: ACoord -> BCoord -> (Double, Double) toOffsetCartesianCoords a b = (tx-zx, ty-zy) @@ -59,6 +101,7 @@ toOffsetCartesianCoords a b = (zx,zy) = toCartesianCoords (1/3) (1/3) (tx,ty) = toCartesianCoords a b +-- | Compute ternary coordinates from XY coordinates. fromCartesianCoords :: Double -> Double -> (ACoord, BCoord, CCoord) fromCartesianCoords x y = (a,b,1-a-b) where