diff options
author | Tom Smeding <tom@tomsmeding.com> | 2022-10-16 16:29:18 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2022-10-16 16:29:18 +0200 |
commit | f578ee4a3d2e3357294a5fe83713b5c04ac6096f (patch) | |
tree | 559c29c91d1279f60b0fe5e783651d6dd24a69a7 /render | |
parent | 4c8c2f99a9817fe84ee7626de11736b133c1de1f (diff) |
Consistent pixel type
Diffstat (limited to 'render')
-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 |