Add a unified Graphics.Config datatype

This commit is contained in:
Kiana Sheibani 2021-12-28 14:26:32 -05:00
parent 37ac2e0aef
commit a53e0204c0
3 changed files with 19 additions and 4 deletions

12
Graphics/Config.hs Normal file
View file

@ -0,0 +1,12 @@
module Graphics.Config where
import FRP.Yampa (Time)
import GOL.Rule (Rule)
import Graphics.Gloss (Color)
data Config = Config
{ cellColor :: Color,
rule :: Rule,
tickRate :: Time,
windowSize :: (Int, Int)
}

View file

@ -6,6 +6,7 @@ module Graphics.Display where
import Control.Monad.Representable.Reader
import Data.Maybe (mapMaybe)
import GOL.Space
import Graphics.Config
import Graphics.Gloss
-- * Drawing the display grid
@ -27,7 +28,8 @@ drawCells xs size =
let poss = (,) <$> [0 .. sizex @f -1] <*> [0 .. sizey @f -1]
in mapMaybe (\pos -> drawCell xs pos size) poss
drawGrid :: forall f. DisplayableSpace f => f Bool -> (Int, Int) -> Picture
drawGrid xs (w, h) =
let size = fromIntegral $ if w > h then h `div` sizey @f else w `div` sizex @f
in color white $ pictures $ drawCells xs size
drawGrid :: forall f. DisplayableSpace f => Config -> f Bool -> Picture
drawGrid config xs =
let (w, h) = windowSize config
size = fromIntegral $ if w > h then h `div` sizey @f else w `div` sizex @f
in color (cellColor config) $ pictures $ drawCells xs size

View file

@ -12,6 +12,7 @@ executable main
GOL.Space,
GOL.Engine,
Graphics.GlossUtils,
Graphics.Config,
Graphics.Engine,
Graphics.Display
build-depends: base,