Update Graphics.Display
This commit is contained in:
parent
3a15c34743
commit
37ac2e0aef
|
@ -8,21 +8,26 @@ import Data.Maybe (mapMaybe)
|
|||
import GOL.Space
|
||||
import Graphics.Gloss
|
||||
|
||||
-- * Drawing the display grid
|
||||
|
||||
square :: Float -> Point -> Picture
|
||||
square size (x, y) = translate (x + size / 2) y (rectangleUpperSolid size size)
|
||||
|
||||
squareAtIndex :: (Int, Int) -> Float -> Picture
|
||||
squareAtIndex (x, y) size = square size (fromIntegral x * size, fromIntegral y * size)
|
||||
|
||||
-- * Calculating the display grid
|
||||
|
||||
drawCell :: DisplayableSpace f => f Bool -> (Int, Int) -> Float -> Maybe Picture
|
||||
drawCell xs pos size =
|
||||
if index xs pos
|
||||
then Just $ squareAtIndex pos size
|
||||
else Nothing
|
||||
|
||||
drawGrid :: forall f. DisplayableSpace f => f Bool -> Float -> [Picture]
|
||||
drawGrid xs size =
|
||||
drawCells :: forall f. DisplayableSpace f => f Bool -> Float -> [Picture]
|
||||
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
|
Loading…
Reference in a new issue