From bc27d7187e67c2d1eb674cc50e9572fe3d8af23a Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Wed, 17 Jan 2018 18:30:31 +0000 Subject: [PATCH] Add option to change background color to white --- README.org | 6 +++++- app/Main.hs | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.org b/README.org index e4f0acc..6275992 100644 --- a/README.org +++ b/README.org @@ -51,12 +51,16 @@ command-line arguments, see the output of ~--help~: #+BEGIN_SRC lsystems -- Generate L-systems -Usage: lsystems-exe [LSYSTEM] [-n|--iterations N] [-l|--list-lsystems] +Usage: lsystems-exe [LSYSTEM] [-n|--iterations N] [-c|--color R,G,B] + [-w|--white-background] [-l|--list-lsystems] Generate and draw an L-system Available options: LSYSTEM L-system to generate (default: penroseP3) -n,--iterations N Number of iterations (default: 5) + -c,--color R,G,B Foreground color RGBA + (0-255) (default: RGBA 1.0 1.0 1.0 1.0) + -w,--white-background Use a white background -l,--list-lsystems List all available L-systems -h,--help Show this help text #+END_SRC diff --git a/app/Main.hs b/app/Main.hs index 4c3879e..7a0992c 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -13,6 +13,7 @@ data Options = Options { optionLSystem :: LSystem Char , optionIterations :: Integer , optionColor :: Color + , optionWhiteBg :: Bool } selectLSystem :: [LSystem a] -> String -> Either String (LSystem a) @@ -68,8 +69,14 @@ colorParser = option (eitherReader readRGB) Right _ -> Right $ makeColorI 255 255 255 255 Left s -> Left s +whiteBackground :: Parser Bool +whiteBackground = switch + (long "white-background" + <> short 'w' + <> help "Use a white background") + options :: Parser Options -options = Options <$> lsystem <*> iterations <*> colorParser +options = Options <$> lsystem <*> iterations <*> colorParser <*> whiteBackground opts :: ParserInfo Options opts = info (options <**> listLSystems <**> helper) @@ -77,11 +84,12 @@ opts = info (options <**> listLSystems <**> helper) <> progDesc "Generate and draw an L-system" <> header "lsystems -- Generate L-systems") -createDisplay :: (Eq a, Integral p) => Color -> p -> LSystem a -> IO () -createDisplay c n ls = display (InWindow "L-System" (200, 200) (10, 10)) black (color c pic) +createDisplay :: (Eq a, Integral p) => Color -> Bool -> p -> LSystem a -> IO () +createDisplay fgColor wbg n ls = display (InWindow "L-System" (200, 200) (10, 10)) bgColor (color fgColor pic) where pic = drawLSystem $ iterateLSystem n ls + bgColor = if wbg then white else black main :: IO () main = do - Options ls n c <- execParser opts - createDisplay c n ls + Options ls n fgColor wbg <- execParser opts + createDisplay fgColor wbg n ls