Skip to content

Instantly share code, notes, and snippets.

@leojpod
Created May 22, 2017 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leojpod/b5d56e024ad1c10a8eaaf10fddc4a661 to your computer and use it in GitHub Desktop.
Save leojpod/b5d56e024ad1c10a8eaaf10fddc4a661 to your computer and use it in GitHub Desktop.
Svg version of Board/View.elm
import Svg exposing (Svg, svg, rect, circle)
import Svg.Attributes exposing (x, cx, y, cy, r, fill, width, height, viewBox)
boardDisplay : Board -> Html BoardMsg
boardDisplay board =
svg
[ viewBox "0 0 100 100"
]
(rect [ fill "#FFFFFF", x "0", y "0", width "100", height "100" ] []
:: List.concat (List.indexedMap rowView board)
)
rowView : Int -> List Cell -> List (Svg BoardMsg)
rowView idx row =
List.concat (List.indexedMap (cellView idx) row)
cellView : Int -> Int -> Cell -> List (Svg BoardMsg)
cellView rowIdx colIdx cell =
rect [ x (toString (colIdx * 10)), y (toString (rowIdx * 10)), width "10", height "10", fill "#FFFFFF" ] []
:: (case cell of
Empty ->
[]
Dead ->
[ circle [ cx (toString (colIdx * 10 + 5)), cy (toString (rowIdx * 10 + 5)), r "5", fill "rgb(0, 121, 107)" ] [] ]
Alive ->
[ circle [ cx (toString (colIdx * 10 + 5)), cy (toString (rowIdx * 10 + 5)), r "5", fill "rgb(0, 150, 136)" ] [] ]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment