diff --git a/flake.nix b/flake.nix index 000ce0df1..1208ed376 100644 --- a/flake.nix +++ b/flake.nix @@ -84,6 +84,7 @@ hooks = { deadnix.enable = true; statix.enable = true; + stylish-haskell.enable = true; typos.enable = true; yamllint.enable = true; }; diff --git a/palette-generator/Ai/Evolutionary.hs b/palette-generator/Ai/Evolutionary.hs index 634bfd113..c6a0c8be3 100644 --- a/palette-generator/Ai/Evolutionary.hs +++ b/palette-generator/Ai/Evolutionary.hs @@ -2,12 +2,12 @@ module Ai.Evolutionary ( Species(..), evolve ) where -import Data.Ord ( Down(Down), comparing ) -import Data.Vector ( (!) ) -import qualified Data.Vector as V -import Data.Vector.Algorithms.Intro ( selectBy ) -import System.Random ( randomRIO ) -import Text.Printf ( printf ) +import Data.Ord (Down (Down), comparing) +import Data.Vector ((!)) +import qualified Data.Vector as V +import Data.Vector.Algorithms.Intro (selectBy) +import System.Random (randomRIO) +import Text.Printf (printf) numSurvivors :: Int numSurvivors = 500 @@ -96,7 +96,7 @@ selectSurvivors environment population = shouldContinue :: [Double] -- ^ Fitness history -> Bool shouldContinue (x:y:_) = x /= y -shouldContinue _ = True +shouldContinue _ = True evolutionLoop :: Species e g => e -- ^ Environment diff --git a/palette-generator/Data/Colour.hs b/palette-generator/Data/Colour.hs index db189062f..45dc33d38 100644 --- a/palette-generator/Data/Colour.hs +++ b/palette-generator/Data/Colour.hs @@ -1,13 +1,13 @@ module Data.Colour ( LAB(..), RGB(..), deltaE, lab2rgb, rgb2lab ) where data LAB = LAB { lightness :: Double - , channelA :: Double - , channelB :: Double + , channelA :: Double + , channelB :: Double } -data RGB = RGB { red :: Double +data RGB = RGB { red :: Double , green :: Double - , blue :: Double + , blue :: Double } -- Based on https://github.com/antimatter15/rgb-lab/blob/master/color.js diff --git a/palette-generator/Stylix/Main.hs b/palette-generator/Stylix/Main.hs index d4a49e609..2170d6243 100644 --- a/palette-generator/Stylix/Main.hs +++ b/palette-generator/Stylix/Main.hs @@ -1,13 +1,13 @@ -import Ai.Evolutionary ( evolve ) -import Codec.Picture ( DynamicImage, convertRGB8, readImage ) -import Data.Colour ( lab2rgb ) -import qualified Data.Vector as V -import Stylix.Output ( makeOutputTable ) -import Stylix.Palette ( ) -import System.Environment ( getArgs ) -import System.Exit ( die ) -import System.Random ( setStdGen, mkStdGen ) -import Text.JSON ( encode ) +import Ai.Evolutionary (evolve) +import Codec.Picture (DynamicImage, convertRGB8, readImage) +import Data.Colour (lab2rgb) +import qualified Data.Vector as V +import Stylix.Output (makeOutputTable) +import Stylix.Palette () +import System.Environment (getArgs) +import System.Exit (die) +import System.Random (mkStdGen, setStdGen) +import Text.JSON (encode) -- | Load an image file. loadImage :: String -- ^ Path to the file diff --git a/palette-generator/Stylix/Output.hs b/palette-generator/Stylix/Output.hs index 9d6733cfe..682d42123 100644 --- a/palette-generator/Stylix/Output.hs +++ b/palette-generator/Stylix/Output.hs @@ -1,10 +1,10 @@ module Stylix.Output ( makeOutputTable ) where -import Data.Colour ( RGB(RGB) ) +import Data.Colour (RGB (RGB)) import qualified Data.Vector as V -import Data.Word ( Word8 ) -import Text.JSON ( JSObject, toJSObject ) -import Text.Printf ( printf ) +import Data.Word (Word8) +import Text.JSON (JSObject, toJSObject) +import Text.Printf (printf) toHexNum :: Double -> Word8 toHexNum = truncate diff --git a/palette-generator/Stylix/Palette.hs b/palette-generator/Stylix/Palette.hs index 1102a3382..1b8b0d784 100644 --- a/palette-generator/Stylix/Palette.hs +++ b/palette-generator/Stylix/Palette.hs @@ -1,14 +1,16 @@ -{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE MultiParamTypeClasses #-} module Stylix.Palette ( ) where -import Ai.Evolutionary ( Species(..) ) -import Codec.Picture ( Image(imageWidth, imageHeight), PixelRGB8(PixelRGB8), pixelAt ) -import Data.Colour ( LAB(lightness), RGB(RGB), deltaE, rgb2lab ) -import Data.List ( delete ) -import Data.Vector ( (//) ) -import qualified Data.Vector as V -import System.Random ( randomRIO ) +import Ai.Evolutionary (Species (..)) +import Codec.Picture (Image (imageHeight, imageWidth), + PixelRGB8 (PixelRGB8), pixelAt) +import Data.Colour (LAB (lightness), RGB (RGB), deltaE, rgb2lab) +import Data.List (delete) +import Data.Vector ((//)) +import qualified Data.Vector as V +import System.Random (randomRIO) -- | Extract the primary scale from a palette. primary :: V.Vector a -> V.Vector a @@ -73,9 +75,9 @@ instance Species (String, Image PixelRGB8) (V.Vector LAB) where scheme = case polarity of "either" -> min lightScheme darkScheme - "light" -> lightScheme - "dark" -> darkScheme - _ -> error ("Invalid polarity: " ++ polarity) + "light" -> lightScheme + "dark" -> darkScheme + _ -> error ("Invalid polarity: " ++ polarity) {- For light themes, the background is bright and the text is dark.