Add option to change background color to white
This commit is contained in:
parent
105acfa65e
commit
bc27d7187e
2 changed files with 18 additions and 6 deletions
|
@ -51,12 +51,16 @@ command-line arguments, see the output of ~--help~:
|
||||||
#+BEGIN_SRC
|
#+BEGIN_SRC
|
||||||
lsystems -- Generate L-systems
|
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
|
Generate and draw an L-system
|
||||||
|
|
||||||
Available options:
|
Available options:
|
||||||
LSYSTEM L-system to generate (default: penroseP3)
|
LSYSTEM L-system to generate (default: penroseP3)
|
||||||
-n,--iterations N Number of iterations (default: 5)
|
-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
|
-l,--list-lsystems List all available L-systems
|
||||||
-h,--help Show this help text
|
-h,--help Show this help text
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
18
app/Main.hs
18
app/Main.hs
|
@ -13,6 +13,7 @@ data Options = Options
|
||||||
{ optionLSystem :: LSystem Char
|
{ optionLSystem :: LSystem Char
|
||||||
, optionIterations :: Integer
|
, optionIterations :: Integer
|
||||||
, optionColor :: Color
|
, optionColor :: Color
|
||||||
|
, optionWhiteBg :: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
selectLSystem :: [LSystem a] -> String -> Either String (LSystem a)
|
selectLSystem :: [LSystem a] -> String -> Either String (LSystem a)
|
||||||
|
@ -68,8 +69,14 @@ colorParser = option (eitherReader readRGB)
|
||||||
Right _ -> Right $ makeColorI 255 255 255 255
|
Right _ -> Right $ makeColorI 255 255 255 255
|
||||||
Left s -> Left s
|
Left s -> Left s
|
||||||
|
|
||||||
|
whiteBackground :: Parser Bool
|
||||||
|
whiteBackground = switch
|
||||||
|
(long "white-background"
|
||||||
|
<> short 'w'
|
||||||
|
<> help "Use a white background")
|
||||||
|
|
||||||
options :: Parser Options
|
options :: Parser Options
|
||||||
options = Options <$> lsystem <*> iterations <*> colorParser
|
options = Options <$> lsystem <*> iterations <*> colorParser <*> whiteBackground
|
||||||
|
|
||||||
opts :: ParserInfo Options
|
opts :: ParserInfo Options
|
||||||
opts = info (options <**> listLSystems <**> helper)
|
opts = info (options <**> listLSystems <**> helper)
|
||||||
|
@ -77,11 +84,12 @@ opts = info (options <**> listLSystems <**> helper)
|
||||||
<> progDesc "Generate and draw an L-system"
|
<> progDesc "Generate and draw an L-system"
|
||||||
<> header "lsystems -- Generate L-systems")
|
<> header "lsystems -- Generate L-systems")
|
||||||
|
|
||||||
createDisplay :: (Eq a, Integral p) => Color -> p -> LSystem a -> IO ()
|
createDisplay :: (Eq a, Integral p) => Color -> Bool -> p -> LSystem a -> IO ()
|
||||||
createDisplay c n ls = display (InWindow "L-System" (200, 200) (10, 10)) black (color c pic)
|
createDisplay fgColor wbg n ls = display (InWindow "L-System" (200, 200) (10, 10)) bgColor (color fgColor pic)
|
||||||
where pic = drawLSystem $ iterateLSystem n ls
|
where pic = drawLSystem $ iterateLSystem n ls
|
||||||
|
bgColor = if wbg then white else black
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
Options ls n c <- execParser opts
|
Options ls n fgColor wbg <- execParser opts
|
||||||
createDisplay c n ls
|
createDisplay fgColor wbg n ls
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue