diff --git a/palette-generator/Stylix/Main.hs b/palette-generator/Stylix/Main.hs index 28e4e1c..d85c16e 100644 --- a/palette-generator/Stylix/Main.hs +++ b/palette-generator/Stylix/Main.hs @@ -8,6 +8,13 @@ import System.Environment ( getArgs ) import System.Exit ( die ) import System.Random ( setStdGen, mkStdGen ) import Text.JSON ( encode ) +import Text.Read (readMaybe) + +-- String to float +stringToFloat :: String -> Float +stringToFloat s = case readMaybe s of + Just x -> x + Nothing -> error "Invalid float value" -- | Load an image file. loadImage :: String -- ^ Path to the file @@ -22,7 +29,7 @@ mainProcess (polarity,primaryScaleDark,primaryScaleLight, input, output) = do setStdGen $ mkStdGen 0 image <- loadImage input - palette <- evolve (polarity, primaryScaleDark,primaryScaleLight,convertRGB8 image) + palette <- evolve (polarity,stringToFloat primaryScaleDark,stringToFloat primaryScaleLight,convertRGB8 image) let outputTable = makeOutputTable $ V.map lab2rgb palette writeFile output $ encode outputTable diff --git a/palette-generator/Stylix/Palette.hs b/palette-generator/Stylix/Palette.hs index ebd50fe..1f9f568 100644 --- a/palette-generator/Stylix/Palette.hs +++ b/palette-generator/Stylix/Palette.hs @@ -34,7 +34,7 @@ randomFromImage image = do color = RGB (fromIntegral r) (fromIntegral g) (fromIntegral b) return $ rgb2lab color -instance Species (String,String,String, Image PixelRGB8) (V.Vector LAB) where +instance Species (String,Float,Float, Image PixelRGB8) (V.Vector LAB) where generate (_,_,_, image) = V.replicateM 16 $ randomFromImage image crossover _ a b = return $ alternatingZip a b @@ -84,15 +84,31 @@ instance Species (String,String,String, Image PixelRGB8) (V.Vector LAB) where lightScheme = lightnessError (V.fromList [90, 70, 55, 35, 25, 10, 5, 5]) 40 + // 0.2, 0.133,0.178,0.85,0.93,0.88,1.0,1.0 for 0.1 scale + // f(x) = ax+b for multiplier (light) + // 0.889, 0.111 + // 0.963, 0.037 + // 0.913, 0.087 + // 0.167, 0.833 + // 0.078, 0.922 + // 0.133, 0.087 + // 0.0, 1.0 + // 0.0, 1.0 + {- For dark themes, the background is dark and the text is bright. The accent colours are slightly brighter. -} darkScheme = lightnessError (V.fromList [10, 30, 45, 65, 75, 90, 95, 95]) 60 - - darkerScheme - = lightnessError (V.fromList [5, 10, 15, 60, 70, 80, 95, 95]) 60 - - evenDarkerScheme - = lightnessError (V.fromList [2, 4, 8, 55, 70, 80, 95, 95]) 60 + + // 0.2, 0.133,0.178,0.85,0.93,0.88,1.0,1.0 for 0.1 scale + // f(x) = ax+b for multiplier (dark) + // 0.889, 0.111 + // 0.963, 0.037 + // 0.913, 0.087 + // 0.167, 0.833 + // 0.078, 0.922 + // 0.133, 0.087 + // 0.0, 1.0 + // 0.0, 1.0