mirror of
https://github.com/danth/stylix
synced 2024-11-22 20:23:15 +00:00
ba5565d698
Simplified a lot of code which was unnecessarily generic. Now using monads to manage the state of the random number generator rather than passing it around by hand. Also made some performance improvements, then increased the population size so more combinations are tried in a similar length of time.
27 lines
690 B
Haskell
27 lines
690 B
Haskell
module Stylix.Output ( makeOutputTable ) where
|
|
|
|
import Data.Colour ( RGB(RGB) )
|
|
import qualified Data.Vector as V
|
|
import Data.Word ( Word8 )
|
|
import Text.JSON ( JSObject, toJSObject )
|
|
import Text.Printf ( printf )
|
|
|
|
toHexNum :: Double -> Word8
|
|
toHexNum = truncate
|
|
|
|
{- |
|
|
Convert a colour to a hexdecimal string.
|
|
|
|
>>> toHex (RGB 255 255 255)
|
|
"ffffff"
|
|
-}
|
|
toHex :: RGB -> String
|
|
toHex (RGB r g b) = printf "%02x%02x%02x" (toHexNum r) (toHexNum g) (toHexNum b)
|
|
|
|
-- | Convert a palette to the JSON format expected by Stylix's NixOS modules.
|
|
makeOutputTable :: V.Vector RGB -> JSObject String
|
|
makeOutputTable
|
|
= toJSObject
|
|
. V.toList
|
|
. V.imap (\i c -> (printf "base%02X" i, c))
|
|
. V.map toHex
|