module Reanimate.Builtin.CirclePlot
( circlePlot
) where
import Codec.Picture (PixelRGBA8 (..), generateImage)
import Graphics.SvgTree (Tree)
import Reanimate.Constants (screenHeight)
import Reanimate.Raster (embedImage)
import Reanimate.Svg (flipYAxis, scaleToHeight)
circlePlot :: Int
-> (Double -> Double -> PixelRGBA8)
-> 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)