updated slightly the generation

This commit is contained in:
Yann Esposito (Yogsototh) 2019-10-27 17:23:13 +01:00
parent 174e2bd9db
commit 4791944568
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
2 changed files with 10 additions and 22 deletions

View file

@ -15,38 +15,26 @@ import Lib
main :: IO () main :: IO ()
main = do main = do
args <- getArgs args <- map (HexRGB . toS) <$> getArgs
tpl <- toS <$> LazyIO.readFile "resources/example.tpl" tpl <- toS <$> LazyIO.readFile "resources/example.tpl"
case args of case args of
[dark,light,accent] -> genPaletteFile tpl (dark,light,accent) [dark,light,accent] -> genPaletteFile tpl (dark,light,accent)
["all"] -> traverse_ (genPaletteFile tpl) allColors
_ -> do _ -> do
putText "Please give 3 colors in HEX format, dark, light and an accent color; you have given" putText "Please give 3 colors in HEX format, dark, light and an accent color; you have given"
print args print args
allColors :: [([Char],[Char],[Char])] genPaletteFile :: Text -> (HexRGB,HexRGB,HexRGB) -> IO ()
allColors = [(dark,light,accent) | dark <- colors, light <- colors, accent <- colors ]
where
colors = ['#':r:v:b:[] | r <- ['0','2','4','6','8','A','C','E']
, v <- ['0','2','4','6','8','A','C','E']
, b <- ['0','2','4','6','8','A','C','E']
]
genPaletteFile :: Text -> ([Char],[Char],[Char]) -> IO ()
genPaletteFile tpl (dark,light,accent) = do genPaletteFile tpl (dark,light,accent) = do
let palette = map toS $ genAnnotatedPalette dark light accent let palette = map toS $ genAnnotatedPalette dark light accent
html = Text.replace "$palette$" (Text.intercalate "\n\t" palette) tpl html = Text.replace "$palette$" (Text.intercalate "\n\t" palette) tpl
filename = Format.format "palette-{}-{}-{}.html" (drop 1 dark, filename = Format.format "palette-{}-{}-{}.html" (Text.drop 1 $ unHexRGB dark,
drop 1 light, Text.drop 1 $ unHexRGB light,
drop 1 accent) Text.drop 1 $ unHexRGB accent)
LazyIO.writeFile (toS filename) (toS html) LazyIO.writeFile (toS filename) (toS html)
putText (toS filename) putText (toS filename)
genAnnotatedPalette :: [Char] -> [Char] -> [Char] -> [Text] genAnnotatedPalette :: HexRGB -> HexRGB -> HexRGB -> [Text]
genAnnotatedPalette dark light accent = do genAnnotatedPalette dark light accent = do
let d = HexRGB (toS dark) let palette = map unHexRGB $ genExtendedPalette dark light accent
l = HexRGB (toS light)
c = HexRGB (toS accent)
palette = map unHexRGB $ genExtendedPalette d l c
annotated = zip extendedPaletteLabels palette annotated = zip extendedPaletteLabels palette
map (toS . Format.format "--{}: {};\n") annotated map (toS . Format.format "--{}: {};\n") annotated

View file

@ -21,7 +21,7 @@ import Data.Text (Text)
genBase :: Double -> Double -> Double -> Double -> [HexRGB] genBase :: Double -> Double -> Double -> Double -> [HexRGB]
genBase adark bdark alight blight = genBase adark bdark alight blight =
map (convert . (\n -> mkLAB n (ratio n adark alight) (ratio n bdark blight))) map (convert . (\n -> mkLAB n (ratio n adark alight) (ratio n bdark blight)))
[15.0,20,45,50,60,65,92,97] [10.0,15,40,50,60,70,92,97]
where where
ratio :: Double -> Double -> Double -> Double ratio :: Double -> Double -> Double -> Double
ratio n d l = ((97 - n)*d + (n-15)*l)/82 ratio n d l = ((97 - n)*d + (n-15)*l)/82
@ -43,8 +43,8 @@ genPalette dark light exampleColor = map unHexRGB $
genExtendedColors :: HexRGB -> [HexRGB] genExtendedColors :: HexRGB -> [HexRGB]
genExtendedColors exampleColor = genExtendedColors exampleColor =
let (ColorCoord (l,c,h)) = unLCH (convert exampleColor) let (ColorCoord (l,c,h)) = unLCH (convert exampleColor)
-- [1, 18, 45, 68, 175, 205, 237, 331] hues = [1, 18, 45, 68, 175, 205, 237, 331]
hues = [1, 20, 50, 88, 150, 200, 230, 330] -- hues = map (fromIntegral . (`rem` 360) . floor . (h+)) [i * 45 | i <- [0..7]]
in map (convert . mkLCH 60 c) hues in map (convert . mkLCH 60 c) hues
<> map (convert . mkLCH 35 c) hues <> map (convert . mkLCH 35 c) hues
<> map (convert . mkLCH 85 c) hues <> map (convert . mkLCH 85 c) hues