2021-12-16 20:03:07 +00:00
|
|
|
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 )
|
|
|
|
|
|
|
|
toWord8 :: (RealFrac a) => RGB a -> RGB Word8
|
|
|
|
toWord8 (RGB r g b) = RGB (truncate r) (truncate g) (truncate b)
|
|
|
|
|
2022-04-23 09:36:20 +00:00
|
|
|
toHex :: RGB Word8 -> String
|
|
|
|
toHex (RGB r g b) = printf "%02x%02x%02x" r g b
|
|
|
|
|
2021-12-16 20:03:07 +00:00
|
|
|
makeOutputTable :: (RealFrac a) => V.Vector (RGB a) -> JSObject String
|
|
|
|
makeOutputTable
|
|
|
|
= toJSObject
|
2022-04-23 09:36:20 +00:00
|
|
|
. V.toList
|
2021-12-16 20:03:07 +00:00
|
|
|
. V.imap (\i c -> (printf "base%02X" i, c))
|
2022-04-23 09:36:20 +00:00
|
|
|
. V.map (toHex . toWord8)
|