From f578ee4a3d2e3357294a5fe83713b5c04ac6096f Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 16 Oct 2022 16:29:18 +0200 Subject: Consistent pixel type --- render/Render.hs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'render') 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 -- cgit v1.2.3-70-g09d2