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 = do
args <- getArgs
args <- map (HexRGB . toS) <$> getArgs
tpl <- toS <$> LazyIO.readFile "resources/example.tpl"
case args of
[dark,light,accent] -> genPaletteFile tpl (dark,light,accent)
["all"] -> traverse_ (genPaletteFile tpl) allColors
_ -> do
putText "Please give 3 colors in HEX format, dark, light and an accent color; you have given"
print args
allColors :: [([Char],[Char],[Char])]
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 :: Text -> (HexRGB,HexRGB,HexRGB) -> IO ()
genPaletteFile tpl (dark,light,accent) = do
let palette = map toS $ genAnnotatedPalette dark light accent
html = Text.replace "$palette$" (Text.intercalate "\n\t" palette) tpl
filename = Format.format "palette-{}-{}-{}.html" (drop 1 dark,
drop 1 light,
drop 1 accent)
filename = Format.format "palette-{}-{}-{}.html" (Text.drop 1 $ unHexRGB dark,
Text.drop 1 $ unHexRGB light,
Text.drop 1 $ unHexRGB accent)
LazyIO.writeFile (toS filename) (toS html)
putText (toS filename)
genAnnotatedPalette :: [Char] -> [Char] -> [Char] -> [Text]
genAnnotatedPalette :: HexRGB -> HexRGB -> HexRGB -> [Text]
genAnnotatedPalette dark light accent = do
let d = HexRGB (toS dark)
l = HexRGB (toS light)
c = HexRGB (toS accent)
palette = map unHexRGB $ genExtendedPalette d l c
let palette = map unHexRGB $ genExtendedPalette dark light accent
annotated = zip extendedPaletteLabels palette
map (toS . Format.format "--{}: {};\n") annotated

View file

@ -21,7 +21,7 @@ import Data.Text (Text)
genBase :: Double -> Double -> Double -> Double -> [HexRGB]
genBase adark bdark alight 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
ratio :: Double -> Double -> Double -> Double
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 exampleColor =
let (ColorCoord (l,c,h)) = unLCH (convert exampleColor)
-- [1, 18, 45, 68, 175, 205, 237, 331]
hues = [1, 20, 50, 88, 150, 200, 230, 330]
hues = [1, 18, 45, 68, 175, 205, 237, 331]
-- hues = map (fromIntegral . (`rem` 360) . floor . (h+)) [i * 45 | i <- [0..7]]
in map (convert . mkLCH 60 c) hues
<> map (convert . mkLCH 35 c) hues
<> map (convert . mkLCH 85 c) hues