diff options
Diffstat (limited to 'render/Render.hs')
-rw-r--r-- | render/Render.hs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/render/Render.hs b/render/Render.hs index 9126032..425da1c 100644 --- a/render/Render.hs +++ b/render/Render.hs @@ -4,7 +4,7 @@ {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE ViewPatterns #-} -module Main where +module Main (main) where import qualified Codec.Picture.Png as PNG import qualified Codec.Picture.Types as Pix @@ -18,7 +18,9 @@ import System.Exit (die, exitFailure) import MandelHSlib -colorscheme :: (Ord a, Floating a, RealFrac a) => a -> (Word8, Word8, Word8) +type Colorscheme = Double -> (Word8, Word8, Word8) + +colorscheme :: Colorscheme colorscheme fraction = let x = max 0 fraction ** 0.3 bg = 0.2 * (1 - curve x (-0.1) 0.2) @@ -32,7 +34,7 @@ colorscheme fraction = | x >= end = 1 | otherwise = sin (pi/(end-start) * (x - start) - pi/2) / 2 + 0.5 -renderFractal :: (Ord a, Floating a, RealFrac a, VS.Storable a) => Fractal a -> Pix.Image Pix.PixelRGB8 +renderFractal :: Fractal -> Pix.Image Pix.PixelRGB8 renderFractal (Fractal (w, h) _ arr) = Pix.Image w h $ VS.fromList [val @@ -53,15 +55,11 @@ main = do case args of [infile, outfile] -> do datafile <- BSL.readFile infile - Fractal (w, h) _ arr <- case Ser.runGetLazy Ser.get datafile of + fractal <- case Ser.runGetLazy Ser.get datafile of Left err -> die err Right res -> return res BSL.writeFile outfile $ PNG.encodePng $ - Pix.Image @Pix.PixelRGB8 w h $ VS.fromList - [val - | fraction <- VS.toList arr - , let (r, g, b) = colorscheme @Double fraction - , val <- [r, g, b]] + renderFractal fractal _ -> putStr usage >> exitFailure |