Skip to content

Commit

Permalink
treewide: add and apply stylish-haskell
Browse files Browse the repository at this point in the history
Link: danth#519
(cherry picked from commit 439c6cf)
  • Loading branch information
trueNAHO committed Jan 4, 2025
1 parent f55bb0f commit 431752e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 36 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
hooks = {
deadnix.enable = true;
statix.enable = true;
stylish-haskell.enable = true;
typos.enable = true;
yamllint.enable = true;
};
Expand Down
14 changes: 7 additions & 7 deletions palette-generator/Ai/Evolutionary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions palette-generator/Data/Colour.hs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 10 additions & 10 deletions palette-generator/Stylix/Main.hs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions palette-generator/Stylix/Output.hs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 13 additions & 11 deletions palette-generator/Stylix/Palette.hs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 431752e

Please sign in to comment.