never executed always true always false
    1 module HelVM.HelMA.Automata.Piet.Color where
    2 
    3 import           HelVM.HelIO.SwitchEnum
    4 
    5 mixedColor :: MixedColor -> MixedColor -> MixedColor
    6 mixedColor (MixedColor b1 h1) (MixedColor b2 h2) = MixedColor (brightnessChange b1 b2) (hueChange h1 h2)
    7 
    8 brightnessChange :: Brightness -> Brightness -> Brightness
    9 brightnessChange = change 3
   10 
   11 hueChange :: Hue -> Hue -> Hue
   12 hueChange = change 6
   13 
   14 change :: (Bounded e, Enum e) => Int -> e -> e -> e
   15 change i e1 e2 = unsafeEnum $ (fromEnum e2 - fromEnum e1) `mod` i
   16 
   17 -- | Constructors
   18 rgb2Color :: (Num a , Eq a) => RGBColor a -> Color
   19 rgb2Color (RGBColor 0xff 0xc0 0xc0) = OtherColor $ MixedColor Light  Red
   20 rgb2Color (RGBColor 0xff 0x00 0x00) = OtherColor $ MixedColor Normal Red
   21 rgb2Color (RGBColor 0xc0 0x00 0x00) = OtherColor $ MixedColor Dark   Red
   22 rgb2Color (RGBColor 0xff 0xff 0xc0) = OtherColor $ MixedColor Light  Yellow
   23 rgb2Color (RGBColor 0xff 0xff 0x00) = OtherColor $ MixedColor Normal Yellow
   24 rgb2Color (RGBColor 0xc0 0xc0 0x00) = OtherColor $ MixedColor Dark   Yellow
   25 rgb2Color (RGBColor 0xc0 0xff 0xc0) = OtherColor $ MixedColor Light  Green
   26 rgb2Color (RGBColor 0x00 0xff 0x00) = OtherColor $ MixedColor Normal Green
   27 rgb2Color (RGBColor 0x00 0xc0 0x00) = OtherColor $ MixedColor Dark   Green
   28 rgb2Color (RGBColor 0xc0 0xff 0xff) = OtherColor $ MixedColor Light  Cyan
   29 rgb2Color (RGBColor 0x00 0xff 0xff) = OtherColor $ MixedColor Normal Cyan
   30 rgb2Color (RGBColor 0x00 0xc0 0xc0) = OtherColor $ MixedColor Dark   Cyan
   31 rgb2Color (RGBColor 0xc0 0xc0 0xff) = OtherColor $ MixedColor Light  Blue
   32 rgb2Color (RGBColor 0x00 0x00 0xff) = OtherColor $ MixedColor Normal Blue
   33 rgb2Color (RGBColor 0x00 0x00 0xc0) = OtherColor $ MixedColor Dark   Blue
   34 rgb2Color (RGBColor 0xff 0xc0 0xff) = OtherColor $ MixedColor Light  Magenta
   35 rgb2Color (RGBColor 0xff 0x00 0xff) = OtherColor $ MixedColor Normal Magenta
   36 rgb2Color (RGBColor 0xc0 0x00 0xc0) = OtherColor $ MixedColor Dark   Magenta
   37 rgb2Color (RGBColor 0x00 0x00 0x00) = Black
   38 rgb2Color (RGBColor 0xff 0xff 0xff) = White
   39 rgb2Color  _                        = White
   40 
   41 -- | Types
   42 data RGBColor a = RGBColor a a a
   43 
   44 data Color = Black | White | OtherColor !MixedColor
   45   deriving stock (Show , Read , Eq , Ord)
   46 
   47 data MixedColor = MixedColor !Brightness !Hue
   48   deriving stock (Show , Read , Eq , Ord)
   49 
   50 data Brightness = Light | Normal | Dark
   51   deriving stock (Bounded , Show , Read, Eq , Ord , Enum)
   52 
   53 data Hue = Red | Yellow | Green | Cyan | Blue | Magenta
   54   deriving stock (Bounded , Show , Read, Eq , Ord , Enum)