diff --git a/examples/doc_rgbComponents.hs b/examples/doc_rgbComponents.hs new file mode 100644 index 0000000..59c70fd --- /dev/null +++ b/examples/doc_rgbComponents.hs @@ -0,0 +1,14 @@ +#!/usr/bin/env stack +-- stack runghc --package reanimate +module Main(main) where + +import Reanimate +import Reanimate.Interpolate +import Reanimate.Builtin.Documentation +import Codec.Picture + +main :: IO () +main = reanimate $ docEnv $ animate $ const $ showColorMap $ interpolateRGB8 rgbComponents yellow blue + where + yellow = PixelRGB8 0xFF 0xFF 0x00 + blue = PixelRGB8 0x00 0x00 0xFF diff --git a/src/Reanimate/Builtin/Documentation.hs b/src/Reanimate/Builtin/Documentation.hs index 2ecdf7a..8946e40 100644 --- a/src/Reanimate/Builtin/Documentation.hs +++ b/src/Reanimate/Builtin/Documentation.hs @@ -2,7 +2,9 @@ module Reanimate.Builtin.Documentation where import Reanimate.Animation import Reanimate.Svg +import Reanimate.Raster import Reanimate.Constants +import Codec.Picture docEnv :: Animation -> Animation docEnv = mapA $ \svg -> mkGroup @@ -38,3 +40,11 @@ drawProgress = mkAnimation 2 $ \t -> withFillOpacity 1 $ mkCircle 0.5 ] where widthP = 0.8 + +showColorMap :: (Double -> PixelRGB8) -> SVG +showColorMap f = center $ scaleToSize screenWidth screenHeight $ embedImage img + where + width = 256 + height = 1 + img = generateImage pixelRenderer width height + pixelRenderer x _y = f (fromIntegral x / fromIntegral (width-1))