reanimate-0.2.0.0: src/Reanimate/Builtin/CirclePlot.hs
module Reanimate.Builtin.CirclePlot where
import Codec.Picture
import Graphics.SvgTree (Tree)
import Reanimate.Raster
import Reanimate.Svg
import Reanimate.Constants
-- | Circle plots are scaled to 'screenHeight'.
--
-- Example:
--
-- > circlePlot 500 $ \ang r ->
-- > promotePixel $ toRGB8 $ uncurryRGB sRGB $ hsv (ang/pi*180) r 1
--
-- <<docs/gifs/doc_circlePlot.gif>>
circlePlot :: Int -- ^ Number of diagonal pixels. Only affects quality, not size.
-> (Double -> Double -> PixelRGBA8)
-- ^ Angle and radius in radians and percent respectively.
-> Tree
circlePlot density fn =
scaleToHeight screenHeight $ flipYAxis $
embedImage $ generateImage gen density density
where
cN = fromIntegral $ density `div` 2 - 1
gen x y =
let radius = sqrt ((fromIntegral x-cN)**2 + (fromIntegral y-cN)**2)
ang = atan2 (fromIntegral y-cN) (fromIntegral x-cN)
in if radius > cN
then PixelRGBA8 0 0 0 0
else fn ang (radius / cN)