-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cell.elm
63 lines (43 loc) · 1.02 KB
/
Cell.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module Cell exposing (..)
import Html exposing (Html, div)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
import Html.App as App
-- MODEL
type alias Model =
{ lifeStatus : LifeStatus
, coords : Coords
}
type LifeStatus = Dead | Alive
type alias Coords = ( Int, Int )
init : LifeStatus -> Coords -> Model
init lifeStatus coords =
{ lifeStatus = lifeStatus
, coords = coords
}
-- UPDATE
type Msg
= GoToOtherSide
update : Msg -> Model -> Model
update msg ( { lifeStatus, coords } as model ) =
case msg of
GoToOtherSide ->
case lifeStatus of
Alive -> { model | lifeStatus = Dead }
Dead -> { model | lifeStatus = Alive }
-- VIEW
view : Model -> Html Msg
view ( { lifeStatus, coords } as model ) =
let
color =
case lifeStatus of
Alive -> "blue"
Dead -> "grey"
divStyle =
style
[ ( "background-color", color )
, ( "height", "100%" )
, ( "width", "100%" )
]
in
div [ divStyle ] []